use of org.onap.so.asdc.installer.ResourceStructure in project so by onap.
the class ToscaResourceInstaller method isResourceAlreadyDeployed.
public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed) throws ArtifactInstallerException {
boolean status = false;
ResourceStructure vfResourceStructure = vfResourceStruct;
try {
status = vfResourceStructure.isDeployedSuccessfully();
} catch (RuntimeException e) {
status = false;
logger.debug("Exception :", e);
}
try {
Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
if (existingService != null && !serviceDeployed)
status = true;
if (status) {
logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), vfResourceStructure.getNotification().getServiceName(), BigDecimalVersion.castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()), vfResourceStructure.getNotification().getServiceUUID(), vfResourceStructure.getResourceInstance().getResourceName(), "", "");
WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
watchdogCDStatusRepository.saveAndFlush(wdStatus);
} else {
logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), vfResourceStructure.getNotification().getServiceName(), BigDecimalVersion.castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()), vfResourceStructure.getNotification().getServiceUUID(), vfResourceStructure.getResourceInstance().getResourceName(), "", "");
}
return status;
} catch (Exception e) {
logger.error(LoggingAnchor.THREE, MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), ErrorCode.SchemaError.getValue(), "Exception - isResourceAlreadyDeployed");
throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
}
}
use of org.onap.so.asdc.installer.ResourceStructure in project so by onap.
the class ToscaResourceInstallerTest method createServiceTest.
@Test
public void createServiceTest() {
ToscaResourceStructure toscaResourceStructure = mock(ToscaResourceStructure.class);
ResourceStructure resourceStructure = mock(ResourceStructure.class);
Metadata metadata = mock(Metadata.class);
INotificationData notification = mock(INotificationData.class);
doReturn("e2899e5c-ae35-434c-bada-0fabb7c1b44d").when(toscaResourceStructure).getServiceVersion();
doReturn(metadata).when(toscaResourceStructure).getServiceMetadata();
doReturn("production").when(notification).getWorkloadContext();
doReturn(notification).when(resourceStructure).getNotification();
String serviceType = "test-type";
String serviceRole = "test-role";
String category = "Network L4+";
String description = "Customer Orderable service description";
String name = "Customer Orderable Service";
String uuid = "72db5868-4575-4804-b546-0b0d3c3b5ac6";
String invariantUUID = "6f30bbe3-4590-4185-a7e0-4f9610926c6f";
String namingPolicy = "naming Policy";
String ecompGeneratedNaming = "true";
String environmentContext = "General_Revenue-Bearing";
doReturn(serviceType).when(metadata).getValue("serviceType");
doReturn(serviceRole).when(metadata).getValue("serviceRole");
doReturn(category).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
doReturn(description).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION);
doReturn(name).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
doReturn(uuid).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
doReturn(environmentContext).when(metadata).getValue(metadata.getValue("environmentContext"));
doReturn(invariantUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
doReturn(namingPolicy).when(metadata).getValue("namingPolicy");
doReturn(ecompGeneratedNaming).when(metadata).getValue("ecompGeneratedNaming");
ISdcCsarHelper iSdcCsarHelper = mock(ISdcCsarHelper.class);
List<Input> serviceInputs = new ArrayList<Input>();
LinkedHashMap<String, Object> value = new LinkedHashMap<String, Object>();
value.put("controller_actor", "SO-REF-DATA");
value.put("type", "string");
Input input = new Input("controller_actor", value, null);
serviceInputs.add(0, input);
value = new LinkedHashMap<String, Object>();
value.put("cds_model_version", "v1.4.0");
value.put("type", "string");
input = new Input("cds_model_version", value, null);
serviceInputs.add(1, input);
value = new LinkedHashMap<String, Object>();
value.put("cds_model_name", "Blueprint140");
value.put("type", "string");
input = new Input("cds_model_name", value, null);
serviceInputs.add(2, input);
value = new LinkedHashMap<String, Object>();
value.put("skip_post_instantiation_configuration", "false");
value.put("type", "boolean");
input = new Input("skip_post_instantiation_configuration", value, null);
serviceInputs.add(3, input);
doReturn(iSdcCsarHelper).when(toscaResourceStructure).getSdcCsarHelper();
doReturn(serviceInputs).when(iSdcCsarHelper).getServiceInputs();
Service service = toscaInstaller.createService(toscaResourceStructure, resourceStructure);
assertNotNull(service);
verify(toscaResourceStructure, times(2)).getServiceVersion();
assertNotNull(service.getNamingPolicy());
assertEquals(serviceType, service.getServiceType());
assertEquals(serviceRole, service.getServiceRole());
assertEquals(category, service.getCategory());
assertEquals(description, service.getDescription());
assertEquals(uuid, service.getModelUUID());
assertEquals(invariantUUID, service.getModelInvariantUUID());
assertEquals(namingPolicy, service.getNamingPolicy());
assertTrue(service.getOnapGeneratedNaming());
}
use of org.onap.so.asdc.installer.ResourceStructure in project so by onap.
the class ASDCController method processNsstNotification.
private void processNsstNotification(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
try {
String category = serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
boolean isNeedInital = (category.contains("NSST") || category.equalsIgnoreCase("TN Network Requirement")) && iNotif.getResources().isEmpty();
if (isNeedInital) {
String artifactContent = null;
List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
Optional<IArtifactInfo> artifactOpt = serviceArtifacts.stream().filter(e -> e.getArtifactType().equalsIgnoreCase("WORKFLOW")).findFirst();
if (artifactOpt.isPresent()) {
IArtifactInfo artifactInfo = artifactOpt.get();
logger.debug("Ready to parse this serviceArtifactUUID: " + artifactInfo.getArtifactUUID());
String filePath = Paths.get(getMsoConfigPath(), "ASDC", artifactInfo.getArtifactVersion(), artifactInfo.getArtifactName()).normalize().toString();
ZipParser zipParserInstance = ZipParser.getInstance();
artifactContent = zipParserInstance.parseJsonForZip(filePath);
logger.debug("serviceArtifact parsing success! serviceArtifactUUID: " + artifactInfo.getArtifactUUID());
ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance());
resourceStructure.setResourceType(ResourceType.OTHER);
toscaInstaller.installNsstService(toscaResourceStructure, (VfResourceStructure) resourceStructure, artifactContent);
} else {
logger.debug("serviceArtifact is null");
toscaInstaller.installNsstService(toscaResourceStructure, null, null);
}
}
} catch (IOException e) {
logger.error("serviceArtifact parse failure for service uuid: " + serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
} catch (Exception e) {
logger.error("error NSST process resource failure ", e);
}
}
use of org.onap.so.asdc.installer.ResourceStructure in project so by onap.
the class ASDCController method getResourceStructure.
private ResourceStructure getResourceStructure(INotificationData iNotif, IResourceInstance resource, String resourceType) {
if ("VF".equals(resourceType)) {
return new VfResourceStructure(iNotif, resource);
}
if ("PNF".equals(resourceType)) {
return new PnfResourceStructure(iNotif, resource);
}
logger.info("No resources found for Service: {}", iNotif.getServiceUUID());
ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance());
resourceStructure.setResourceType(ResourceType.OTHER);
return resourceStructure;
}
use of org.onap.so.asdc.installer.ResourceStructure in project so by onap.
the class ASDCController method processResourceNotification.
protected void processResourceNotification(INotificationData iNotif) {
// For each artifact, create a structure describing the VFModule in a ordered flat level
ResourceStructure resourceStructure = null;
String msoConfigPath = getMsoConfigPath();
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath);
DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK;
String errorMessage = null;
boolean serviceDeployed = false;
try {
this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
if (isCsarAlreadyDeployed(iNotif, toscaResourceStructure)) {
return;
}
// process NsstResource
this.processNsstNotification(iNotif, toscaResourceStructure);
if (iNotif.getResources().isEmpty()) {
logger.error("Service Model contains no resources.");
return;
}
for (IResourceInstance resource : iNotif.getResources()) {
String resourceType = resource.getResourceType();
boolean hasVFResource = false;
logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID());
resourceStructure = getResourceStructure(iNotif, resource, resourceType);
try {
if (!this.checkResourceAlreadyDeployed(resourceStructure, serviceDeployed)) {
logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure.getResourceInstance().getResourceUUID());
if ("VF".equals(resourceType)) {
hasVFResource = true;
for (IArtifactInfo artifact : resource.getArtifacts()) {
IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, iNotif.getDistributionID());
if (resultArtifact == null) {
continue;
}
if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
logger.debug("VF_MODULE_ARTIFACT: " + new String(resultArtifact.getArtifactPayload(), StandardCharsets.UTF_8));
logger.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(((VfResourceStructure) resourceStructure).decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
}
if (!ASDCConfiguration.WORKFLOW.equals(artifact.getArtifactType())) {
resourceStructure.addArtifactToStructure(distributionClient, artifact, resultArtifact);
} else {
writeArtifactToFile(artifact, resultArtifact);
logger.debug("Adding workflow artifact to structure: " + artifact.getArtifactName());
resourceStructure.addWorkflowArtifactToStructure(artifact, resultArtifact);
}
}
// Deploy VF resource and artifacts
logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
this.deployResourceStructure(resourceStructure, toscaResourceStructure);
serviceDeployed = true;
}
}
} catch (ArtifactInstallerException e) {
deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
errorMessage = e.getMessage();
logger.error("Exception occurred", e);
}
if (!hasVFResource) {
logger.debug("No resources found for Service: " + iNotif.getServiceUUID());
logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
try {
this.deployResourceStructure(resourceStructure, toscaResourceStructure);
serviceDeployed = true;
} catch (ArtifactInstallerException e) {
deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
errorMessage = e.getMessage();
logger.error("Exception occurred", e);
}
}
}
this.sendCsarDeployNotification(resourceStructure, toscaResourceStructure, deployStatus, errorMessage);
} catch (ASDCDownloadException | UnsupportedEncodingException e) {
logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", ErrorCode.BusinessProcessError.getValue(), "Exception in processResourceNotification", e);
}
}
Aggregations