- if (tryGet.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {\r
- // this vnf-image not already in the db, need to add\r
- // only do this on 404 bc other error responses could mean there\r
- // are problems that\r
- // you might not want to try to PUT against\r
-\r
- VnfImage image = new VnfImage();\r
- image.setApplication(application);\r
- image.setApplicationVendor(applicationVendor);\r
- image.setApplicationVersion(applicationVersion);\r
- String uuid = UUID.randomUUID().toString();\r
- image.setUuid(uuid); // need to create uuid\r
-\r
- System.setProperty("javax.xml.bind.context.factory",\r
- "org.eclipse.persistence.jaxb.JAXBContextFactory");\r
- JAXBContext jaxbContext = JAXBContext.newInstance(VnfImage.class);\r
- Marshaller marshaller = jaxbContext.createMarshaller();\r
- marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");\r
- marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);\r
- marshaller.setProperty(MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);\r
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);\r
- StringWriter writer = new StringWriter();\r
- marshaller.marshal(image, writer);\r
- String payload = writer.toString();\r
-\r
- String putUrl = config.getAaiBaseUrl() + config.getAaiVnfImageUrl() + "/vnf-image/"\r
- + uuid;\r
-\r
- ClientResponse putResp = restClient.putResource(putUrl, payload, distributionId,\r
- MimeType.JSON);\r
- if (putResp == null\r
- || putResp.getStatus() != Response.Status.CREATED.getStatusCode()) {\r
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR,\r
- "Ingestion failed on vnf-image " + imageId + ". Rolling back distribution.");\r
- failureCleanup(putImages, restClient, distributionId);\r
- return false;\r
- }\r
- putImages.add(image);\r
- logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, imageId + " successfully ingested.");\r
- } else if (tryGet.getStatus() == Response.Status.OK.getStatusCode()) {\r
- logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,\r
- imageId + " already exists. Skipping ingestion.");\r
+\r
+ int resultCode = tryGet.getResultCode();\r
+ if (resultCode == Response.Status.NOT_FOUND.getStatusCode()) {\r
+ // This vnf-image is missing, so add it\r
+ boolean success = putVnfImage(restClient, dataItem, distributionId);\r
+ if (!success) {\r
+ throw new VnfImageException(imageId.toString());\r
+ }\r
+ completedArtifacts.add(vnfcArtifact);\r
+ logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, imageId + " successfully ingested.");\r
+ } else if (resultCode == Response.Status.OK.getStatusCode()) {\r
+ logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, imageId + " already exists. Skipping ingestion.");\r