diff options
Diffstat (limited to 'adapters')
5 files changed, 90 insertions, 40 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 051d8134f1..076e03b6b3 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -31,8 +31,6 @@ import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilderException; import javax.ws.rs.core.Response; -import org.onap.so.db.catalog.beans.CloudIdentity; -import org.onap.so.utils.CryptoUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.onap.so.adapters.vdu.CloudInfo; @@ -64,6 +62,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.heat.model.CreateStackParam; @@ -173,35 +173,20 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ CreateStackParam stack = createStackParam(stackName, heatTemplate, stackInputs, timeoutMinutes, environment, files, heatFiles); MulticloudRequest multicloudRequest= new MulticloudRequest(); - HttpEntity<MulticloudRequest> request = null; try { multicloudRequest.setGenericVnfId(genericVnfId); multicloudRequest.setVfModuleId(vfModuleId); - multicloudRequest.setOofDirectives(oofDirectives); - multicloudRequest.setSdncDirectives(sdncDirectives); + multicloudRequest.setOofDirectives(JSON_MAPPER.readTree(oofDirectives)); + multicloudRequest.setSdncDirectives(JSON_MAPPER.readTree(sdncDirectives)); multicloudRequest.setTemplateType(templateType); if (logger.isDebugEnabled()) { logger.debug(String.format("Stack Template Data is: %s", stack.toString().substring(16))); } - multicloudRequest.setTemplateData(JSON_MAPPER.writeValueAsString(stack)); + multicloudRequest.setTemplateData(stack); if (logger.isDebugEnabled()) { logger.debug(String.format("Multicloud Request is: %s", multicloudRequest.toString())); } - - CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> - new MsoCloudSiteNotFound(cloudSiteId)); - CloudIdentity cloudIdentity = cloudSite.getIdentityService(); - HttpHeaders headers = new HttpHeaders(); - headers.set ("X-Auth-User", cloudIdentity.getMsoId ()); - headers.set ("X-Auth-Key", CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass ())); - headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString()); - headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString()); - - if (logger.isDebugEnabled()) { - logger.debug(String.format("Multicloud Request Headers: %s", headers.toString())); - } - request = new HttpEntity<>(multicloudRequest, headers); } catch (Exception e) { logger.debug("ERROR making multicloud JSON body ", e); } @@ -211,7 +196,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ } RestClient multicloudClient = getMulticloudClient(multicloudEndpoint); - Response response = multicloudClient.post(request); + Response response = multicloudClient.post(multicloudRequest); StackInfo createInfo = new StackInfo(); createInfo.setName(stackName); @@ -223,7 +208,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ if (logger.isDebugEnabled()) { logger.debug("Multicloud Create Response Body: " + multicloudResponseBody); } - return getStackStatus(cloudSiteId, tenantId, multicloudResponseBody.getWorkloadId(), pollForCompletion, timeoutMinutes, backout); + return getStackStatus(cloudSiteId, tenantId, createInfo.getCanonicalName(), pollForCompletion, timeoutMinutes, backout); } else { createInfo.setStatus(HeatStatus.FAILED); createInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase()); @@ -609,7 +594,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ private RestClient getMulticloudClient(String endpoint) { RestClient client = null; try { - client= new HttpClient(UriBuilder.fromUri(endpoint).build().toURL(), + client = new HttpClient(UriBuilder.fromUri(endpoint).build().toURL(), MediaType.APPLICATION_JSON.toString(), TargetEntity.MULTICLOUD); } catch (MalformedURLException e) { logger.debug(String.format("Encountered malformed URL error getting multicloud rest client %s", e.getMessage())); @@ -715,7 +700,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ try { // Delete the Multicloud stack - StackInfo stackInfo = deleteStack (tenantId, cloudSiteId, instanceId); + StackInfo stackInfo = deleteStack (cloudSiteId, tenantId, instanceId); // Populate a VduInstance based on the deleted Cloudify Deployment object VduInstance vduInstance = stackInfoToVduInstance(stackInfo); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java index fefc0951f6..4204813cec 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java @@ -24,6 +24,9 @@ import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.JsonNode; +import com.woorea.openstack.heat.model.CreateStackParam; + import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @@ -43,13 +46,13 @@ public class MulticloudRequest implements Serializable { @JsonProperty("vf-module-id") private String vfModuleId; @JsonProperty("oof_directives") - private String oofDirectives; + private JsonNode oofDirectives; @JsonProperty("sdnc_directives") - private String sdncDirectives; + private JsonNode sdncDirectives; @JsonProperty("template_type") private String templateType; @JsonProperty("template_data") - private String templateData; + private CreateStackParam templateData; @JsonProperty("generic-vnf-id") @@ -73,22 +76,22 @@ public class MulticloudRequest implements Serializable { } @JsonProperty("oof_directives") - public String getOofDirectives() { + public JsonNode getOofDirectives() { return oofDirectives; } @JsonProperty("oof_directives") - public void setOofDirectives(String oofDirectives) { + public void setOofDirectives(JsonNode oofDirectives) { this.oofDirectives = oofDirectives; } @JsonProperty("sdnc_directives") - public String getSdncDirectives() { + public JsonNode getSdncDirectives() { return sdncDirectives; } @JsonProperty("sdnc_directives") - public void setSdncDirectives(String sdncDirectives) { + public void setSdncDirectives(JsonNode sdncDirectives) { this.sdncDirectives = sdncDirectives; } @@ -103,12 +106,12 @@ public class MulticloudRequest implements Serializable { } @JsonProperty("template_data") - public String getTemplateData() { + public CreateStackParam getTemplateData() { return templateData; } @JsonProperty("template_data") - public void setTemplateData(String templateData) { + public void setTemplateData(CreateStackParam templateData) { this.templateData = templateData; } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java index 5cd2559ef2..eaf3e125a1 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java @@ -340,14 +340,21 @@ public class CatalogDbAdapterRest { uuid = modelUUID; logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: {}" , uuid); Service serv =serviceRepo.findOneByModelUUID(uuid); - ret.setService(serv); + + if (serv != null) { + ret.setNetworkResourceCustomizations(new ArrayList(serv.getNetworkCustomizations())); + ret.setVnfResourceCustomizations(new ArrayList(serv.getVnfCustomizations())); + ret.setAllottedResourceCustomizations(new ArrayList(serv.getAllottedCustomizations())); + } + ret.setService(serv); } else if (modelInvariantUUID != null && !"".equals(modelInvariantUUID)) { uuid = modelInvariantUUID; if (modelVersion != null && !"".equals(modelVersion)) { logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: {} serviceModelVersion: {}",uuid, modelVersion); Service serv = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(modelVersion, uuid); - ret.setService(serv); + + ret.setService(serv); } else { logger.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: {}" , uuid); diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index 5c7b64d054..5e2bd82776 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java @@ -20,9 +20,11 @@ package org.onap.so.db.catalog.client; +import java.util.List; +import java.util.UUID; + import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.adapters.catalogdb.CatalogDBApplication; @@ -30,6 +32,7 @@ import org.onap.so.db.catalog.beans.AuthenticationType; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.CloudifyManager; +import org.onap.so.db.catalog.beans.ExternalServiceToInternalService; import org.onap.so.db.catalog.beans.InstanceGroup; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; import org.onap.so.db.catalog.beans.ServerType; @@ -49,10 +52,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import java.net.URI; -import java.util.List; -import java.util.UUID; - @RunWith(SpringRunner.class) @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") @@ -414,4 +413,57 @@ public class CatalogDbClientTest { Assert.assertEquals("regionId", getCloudSite.getRegionId()); Assert.assertEquals("RANDOMID", getCloudSite.getIdentityServiceId()); } + @Test + public void testGetServiceByModelName() { + Service service = client.getServiceByModelName("MSOTADevInfra_Test_Service"); + Assert.assertNotNull(service); + Assert.assertNotNull(service.getModelVersion()); + Assert.assertNotNull(service.getModelInvariantUUID()); + Assert.assertEquals("MSOTADevInfra_Test_Service", service.getModelName()); + Assert.assertEquals("NA", service.getServiceRole()); + } + + @Test + public void testGetServiceByModelNameNotFound() { + Service service = client.getServiceByModelName("Not_Found"); + Assert.assertNull(service); + } + + @Test + public void testGetServiceByModelUUID() { + Service service = client.getServiceByModelUUID("5df8b6de-2083-11e7-93ae-92361f002679"); + Assert.assertNotNull(service); + Assert.assertNotNull(service.getModelVersion()); + Assert.assertNotNull(service.getModelInvariantUUID()); + Assert.assertEquals("5df8b6de-2083-11e7-93ae-92361f002679", service.getModelUUID()); + Assert.assertEquals("NA", service.getServiceRole()); + } + + @Test + public void testGetServiceByModelUUIDNotFound() { + Service service = client.getServiceByModelUUID("Not_Found"); + Assert.assertNull(service); + } + + @Test + public void testFindServiceRecipeByActionAndServiceModelUUID() { + ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("createInstance","4694a55f-58b3-4f17-92a5-796d6f5ffd0d" ); + Assert.assertNotNull(serviceRecipe); + Assert.assertNotNull(serviceRecipe.getServiceModelUUID()); + Assert.assertNotNull(serviceRecipe.getAction()); + Assert.assertEquals("/mso/async/services/CreateGenericALaCarteServiceInstance", serviceRecipe.getOrchestrationUri()); + Assert.assertEquals("MSOTADevInfra aLaCarte", serviceRecipe.getDescription()); + } + + @Test + public void testFindServiceRecipeByActionAndServiceModelUUIDNotFound() { + ServiceRecipe serviceRecipe = client.findServiceRecipeByActionAndServiceModelUUID("not_found","5df8b6de-2083-11e7-93ae-test" ); + Assert.assertNull(serviceRecipe); + } + + @Test + public void testFindExternalToInternalServiceByServiceNameNotFound() { + ExternalServiceToInternalService externalServiceToInternalService = client.findExternalToInternalServiceByServiceName("Not_Found"); + Assert.assertNull(externalServiceToInternalService); + } } diff --git a/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql b/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql index d5cdb18a0c..c8475564a4 100644 --- a/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql +++ b/adapters/mso-catalog-db-adapter/src/test/resources/db/migration/afterMigrate.sql @@ -60,6 +60,9 @@ insert into tosca_csar(artifact_uuid, name, version, description, artifact_check insert into service(model_uuid, model_name, model_invariant_uuid, model_version, description, creation_timestamp, tosca_csar_artifact_uuid, service_type, service_role, environment_context, workload_context) values ('5df8b6de-2083-11e7-93ae-92361f002671', 'MSOTADevInfra_vSAMP10a_Service', '9647dfc4-2083-11e7-93ae-92361f002671', '1.0', 'MSO aLaCarte Vfmodule with addon', '2017-04-14 13:42:39', '0513f839-459d-46b6-aa3d-2edfef89a079', 'NA', 'NA', 'Luna', 'Oxygen'); +insert into service(model_uuid, model_name, model_invariant_uuid, model_version, description, creation_timestamp, tosca_csar_artifact_uuid, service_type, service_role, environment_context, workload_context) values +('5df8b6de-2083-11e7-93ae-92361f002679', 'MSOTADevInfra_Test_Service', '9647dfc4-2083-11e7-93ae-92361f002673', '3.0', 'MSO aLaCarte Vfmodule with addon', '2017-04-14 13:42:39', '0513f839-459d-46b6-aa3d-2edfef89a079', 'NA', 'NA', 'Luna', 'Oxygen'); + insert into tosca_csar(ARTIFACT_UUID,NAME,VERSION,DESCRIPTION,ARTIFACT_CHECKSUM,URL,CREATION_TIMESTAMP) values ('266eaf78-af74-45cd-83ec-9c477f189dc1','service-NetworkCollectionSvc0106-csar.csar','1','TOSCA definition package of the asset','OGQ1M2QyYjU0OWMzZTY4MWVlYTNhOWIxNmQ2NjEyZDQ=','/sdc/v1/catalog/services/NetworkCollectionSvc0106/1.0/artifacts/service-NetworkCollectionSvc0106-csar.csar','2018-06-01 16:06:52'); insert into service(model_uuid, model_name, model_invariant_uuid, model_version, description, creation_timestamp, tosca_csar_artifact_uuid, service_type, service_role, environment_context, workload_context) values |