}
}
- boolean doContent = (SubscriptionScope.Full == SubscriptionScope.forCode(this.sub.getScopeType()));
+ boolean doContent = (peerArtifact.getUri() != null) &&
+ (SubscriptionScope.Full == SubscriptionScope.forCode(this.sub.getScopeType()));
if (doContent) {
+ log.info(EELFLoggerDelegate.debugLogger, "Processing content for artifact {}", peerArtifact);
// TODO: we are trying to access the artifact by its identifier which
// is fine in the common case but the uri specified in the artifact
// data is a more flexible approach.
Resource artifactContent = null;
try {
artifactContent = fedClient.downloadArtifact(peerArtifact.getArtifactId());
+ log.info(EELFLoggerDelegate.debugLogger, "Received {} bytes of artifact content", artifactContent.contentLength());
}
catch (Exception x) {
log.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve acumos artifact content", x);
localArtifact.getName(), /* probably wrong */
localArtifact.getVersion(), "", /* should receive this from peer */
artifactContent.contentLength(), artifactContent.getInputStream());
+ log.info(EELFLoggerDelegate.debugLogger, "Wrote artifact content locally to {}", uploadInfo.getArtifactMvnPath());
}
catch (Exception x) {
log.error(EELFLoggerDelegate.errorLogger,
if (doUpdate) {
try {
cdsClient.updateArtifact(localArtifact);
+ log.info(EELFLoggerDelegate.debugLogger, "Local artifact updated with local content reference: {}", localArtifact);
}
catch (HttpStatusCodeException restx) {
log.error(EELFLoggerDelegate.errorLogger,
@ResponseBody
public InputStreamResource downloadSolutionArtifact(HttpServletRequest theHttpRequest,
HttpServletResponse theHttpResponse, @PathVariable("artifactId") String theArtifactId) {
- InputStreamResource inputStreamResource = null;
+ InputStreamResource resource = null;
try {
- inputStreamResource = catalogService.getSolutionRevisionArtifactContent(theArtifactId,
+ resource = catalogService.getSolutionRevisionArtifactContent(theArtifactId,
new ControllerContext());
- theHttpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
- theHttpResponse.setHeader("Pragma", "no-cache");
- theHttpResponse.setHeader("Expires", "0");
- theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+ if (resource == null) {
+ theHttpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ else {
+ theHttpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
+ theHttpResponse.setHeader("Pragma", "no-cache");
+ theHttpResponse.setHeader("Expires", "0");
+ theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+ }
}
catch (Exception x) {
theHttpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
log.error(EELFLoggerDelegate.errorLogger,
"An error occurred while downloading artifact " + theArtifactId, x);
}
- return inputStreamResource;
+ return resource;
}
/** */
/** */
private void encodeArtifact(MLPArtifact theArtifact, HttpServletRequest theRequest) throws URISyntaxException {
- URI requestUri = new URI(theRequest.getRequestURL().toString());
- URI artifactUri = API.ARTIFACT_DOWNLOAD
- .buildUri(
- new URI(requestUri.getScheme(), null, requestUri.getHost(),
- requestUri.getPort(), null, null, null).toString(),
- theArtifact.getArtifactId());
- log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevisionArtifacts: content uri " + artifactUri);
- theArtifact.setUri(artifactUri.toString());
+ if (theArtifact.getUri() != null) {
+ URI requestUri = new URI(theRequest.getRequestURL().toString());
+ URI artifactUri = API.ARTIFACT_DOWNLOAD
+ .buildUri(
+ new URI(requestUri.getScheme(), null, requestUri.getHost(),
+ requestUri.getPort(), null, null, null).toString(),
+ theArtifact.getArtifactId());
+ log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevisionArtifacts: encoded content uri " + artifactUri);
+ theArtifact.setUri(artifactUri.toString());
+ }
}
+
}
* the execution context
* @return resource containing access to the actual artifact content
*/
- public InputStreamResource getSolutionRevisionArtifactContent(String theArtifactId, ServiceContext theContext);
+ public InputStreamResource getSolutionRevisionArtifactContent(String theArtifactId, ServiceContext theContext)
+ throws ServiceException;
}
import org.acumos.federation.gateway.config.EELFLoggerDelegate;
import org.acumos.federation.gateway.service.CatalogService;
import org.acumos.federation.gateway.service.ServiceContext;
+import org.acumos.federation.gateway.service.ServiceException;
import org.acumos.federation.gateway.util.Utils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.core.io.InputStreamResource;
-import org.springframework.stereotype.Service;
-import org.springframework.context.annotation.Conditional;
import org.acumos.nexus.client.NexusArtifactClient;
import org.acumos.cds.domain.MLPSolutionRevision;
import org.acumos.cds.transport.RestPageResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.stereotype.Service;
+import org.springframework.context.annotation.Conditional;
+
+
/**
* CDS based implementation of the CatalogService.
*
return mlpArtifacts;
}
+ /**
+ * @return a resource containing the content or null if the artifact has no content
+ * @throws ServiceException if failing to retrieve artifact information or retrieve content
+ */
@Override
- public InputStreamResource getSolutionRevisionArtifactContent(String theArtifactId, ServiceContext theContext) {
+ public InputStreamResource getSolutionRevisionArtifactContent(String theArtifactId, ServiceContext theContext) throws ServiceException {
InputStreamResource streamResource = null;
- ByteArrayOutputStream byteArrayOutputStream = null;
try {
ICommonDataServiceRestClient cdsClient = getClient();
- MLPArtifact mlpArtifact = cdsClient.getArtifact(theArtifactId);
-
- NexusArtifactClient artifactClient = this.clients.getNexusClient();
-
- byteArrayOutputStream = artifactClient.getArtifact(mlpArtifact.getUri());
- InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-
- // Plain Old Java. Sprint 3 will use try resource handling
- if (inputStream != null) {
- streamResource = new InputStreamResource(inputStream
- /*
- * , some_description
- */);
+ MLPArtifact artifact = cdsClient.getArtifact(theArtifactId);
+
+ if (artifact.getUri() != null) {
+ NexusArtifactClient artifactClient = this.clients.getNexusClient();
+ streamResource = new InputStreamResource(
+ new ByteArrayInputStream(
+ artifactClient.getArtifact(artifact.getUri()).toByteArray()
+ ));
}
- if (byteArrayOutputStream != null) {
- byteArrayOutputStream.close();
- }
-
}
catch (Exception x) {
- log.error(EELFLoggerDelegate.errorLogger, "getSolutionRevisionArtifactiContent", x);
+ log.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve artifact content for artifact " + theArtifactId, x);
+ throw new ServiceException("Failed to retrieve artifsact content for artifact " + theArtifactId, x);
}
return streamResource;
}
import org.acumos.federation.gateway.config.EELFLoggerDelegate;
import org.acumos.federation.gateway.service.CatalogService;
import org.acumos.federation.gateway.service.ServiceContext;
+import org.acumos.federation.gateway.service.ServiceException;
import org.acumos.federation.gateway.util.Utils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.BeanInitializationException;
-import org.springframework.core.env.Environment;
-import org.springframework.core.io.InputStreamResource;
-import org.springframework.stereotype.Service;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.boot.context.properties.ConfigurationProperties;
import org.acumos.cds.AccessTypeCode;
import org.acumos.cds.ValidationStatusCode;
import org.acumos.cds.domain.MLPSolutionRevision;
import org.acumos.cds.transport.RestPageResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.core.env.Environment;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.stereotype.Service;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+
/**
*
*
}
@Override
- public InputStreamResource getSolutionRevisionArtifactContent(String theArtifactId, ServiceContext theContext) {
+ public InputStreamResource getSolutionRevisionArtifactContent(String theArtifactId, ServiceContext theContext)
+ throws ServiceException {
log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevisionArtifactContent");
// cumbersome
return new InputStreamResource(new URI(artifact.getUri()).toURL().openStream());
} catch (Exception x) {
log.debug(EELFLoggerDelegate.debugLogger,
- "failed to load content from " + artifact.getUri(), x);
+ "failed to load artifact content from " + artifact.getUri(), x);
+ throw new ServiceException("Failed to retrieve content for artifact " + theArtifactId, x);
}
}
}