Search in sources :

Example 1 with AllottedResourceCustomization

use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.

the class ToscaResourceInstaller method processAllottedResources.

protected void processAllottedResources(List<IEntityDetails> arEntityDetails, ToscaResourceStructure toscaResourceStruct, Service service) throws ArtifactInstallerException {
    List<IEntityDetails> pnfAREntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.PNF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
    for (IEntityDetails pnfEntity : pnfAREntityList) {
        Metadata metadata = pnfEntity.getMetadata();
        String category = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
        if (ALLOTTED_RESOURCE.equalsIgnoreCase(category)) {
            arEntityDetails.add(pnfEntity);
        }
    }
    if (arEntityDetails != null) {
        for (IEntityDetails arEntity : arEntityDetails) {
            AllottedResourceCustomization allottedResource = createAllottedResource(arEntity, toscaResourceStruct, service);
            String resourceInput = getResourceInput(toscaResourceStruct, allottedResource.getModelCustomizationUUID());
            if (!"{}".equals(resourceInput)) {
                allottedResource.setResourceInput(resourceInput);
            }
            if (!service.getAllottedCustomizations().contains(allottedResource)) {
                service.getAllottedCustomizations().add(allottedResource);
            }
        }
    }
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization)

Example 2 with AllottedResourceCustomization

use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.

the class ToscaResourceInstaller method createAllottedResourceCustomization.

protected AllottedResourceCustomization createAllottedResourceCustomization(IEntityDetails arEntity, ToscaResourceStructure toscaResourceStructure) {
    AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
    allottedResourceCustomization.setModelCustomizationUUID(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
    allottedResourceCustomization.setModelInstanceName(arEntity.getName());
    allottedResourceCustomization.setNfFunction(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
    allottedResourceCustomization.setNfNamingCode(getLeafPropertyValue(arEntity, "nf_naming_code"));
    allottedResourceCustomization.setNfRole(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFROLE));
    allottedResourceCustomization.setNfType(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
    EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build();
    TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(allottedResourceCustomization.getModelCustomizationUUID()).build();
    List<IEntityDetails> vfcEntities = toscaResourceStructure.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, false);
    if (vfcEntities != null) {
        for (IEntityDetails vfcEntity : vfcEntities) {
            allottedResourceCustomization.setProvidingServiceModelUUID(getLeafPropertyValue(vfcEntity, "providing_service_uuid"));
            allottedResourceCustomization.setProvidingServiceModelInvariantUUID(getLeafPropertyValue(vfcEntity, "providing_service_invariant_uuid"));
            allottedResourceCustomization.setProvidingServiceModelName(getLeafPropertyValue(vfcEntity, "providing_service_name"));
        }
    }
    List<CapabilityAssignment> capAssignmentList = arEntity.getCapabilities();
    if (capAssignmentList != null) {
        for (CapabilityAssignment arCapability : capAssignmentList) {
            if (arCapability != null) {
                String capabilityName = arCapability.getName();
                if (capabilityName.equals(SCALABLE)) {
                    allottedResourceCustomization.setMinInstances(Integer.getInteger(getCapabilityLeafPropertyValue(arCapability, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
                    allottedResourceCustomization.setMinInstances(Integer.getInteger(getCapabilityLeafPropertyValue(arCapability, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
                }
            }
        }
    }
    return allottedResourceCustomization;
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) TopologyTemplateQuery(org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery) CapabilityAssignment(org.onap.sdc.toscaparser.api.CapabilityAssignment) EntityQuery(org.onap.sdc.tosca.parser.elements.queries.EntityQuery) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization)

Example 3 with AllottedResourceCustomization

use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.

the class ASDCRestInterfaceTest method testAllottedResourceService.

@Test
@Transactional
public void testAllottedResourceService() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File("src/test/resources/resource-examples/allottedresource/notif-portm.json"), NotificationDataImpl.class);
    headers.add("resource-location", "src/test/resources/resource-examples/allottedresource/");
    HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    AllottedResource expectedService = new AllottedResource();
    expectedService.setDescription("rege1802pnf");
    expectedService.setModelInvariantUUID("b8f83c3f-077c-4e2c-b489-c66382060436");
    expectedService.setModelName("rege1802pnf");
    expectedService.setModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d");
    expectedService.setModelVersion("1.0");
    expectedService.setSubcategory("Contrail Route");
    expectedService.setToscaNodeType("org.openecomp.resource.pnf.Rege1802pnf");
    Set<AllottedResourceCustomization> arCustomizationSet = new HashSet<AllottedResourceCustomization>();
    AllottedResourceCustomization arCustomization = new AllottedResourceCustomization();
    arCustomization.setModelCustomizationUUID("f62bb612-c5d4-4406-865c-0abec30631ba");
    arCustomization.setModelInstanceName("rege1802pnf 0");
    arCustomizationSet.add(arCustomization);
    arCustomization.setAllottedResource(expectedService);
    expectedService.setAllotedResourceCustomization(arCustomizationSet);
    AllottedResource actualResponse = allottedRepo.findResourceByModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d");
    if (actualResponse == null)
        throw new Exception("No Allotted Resource Written to database");
    assertThat(actualResponse, sameBeanAs(expectedService).ignoring("0x1.created").ignoring("0x1.allotedResourceCustomization.created"));
}
Also used : NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) HttpEntity(org.springframework.http.HttpEntity) File(java.io.File) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) HashSet(java.util.HashSet) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 4 with AllottedResourceCustomization

use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.

the class QueryAllottedResourceCustomization method JSON2.

@Override
public String JSON2(boolean isArray, boolean isEmbed) {
    StringBuilder sb = new StringBuilder();
    if (!isEmbed && isArray)
        sb.append("{ ");
    if (isArray)
        sb.append("\"serviceAllottedResources\": [");
    Map<String, String> valueMap = new HashMap<>();
    String sep = "";
    boolean first = true;
    if (this.allottedResourceCustomization != null) {
        for (AllottedResourceCustomization o : allottedResourceCustomization) {
            if (first)
                sb.append("\n");
            first = false;
            boolean arNull = o.getAllottedResource() == null;
            put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName());
            put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUUID());
            put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUUID());
            put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion());
            put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
            put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
            put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType());
            put(valueMap, "ALLOTTED_RESOURCE_TYPE", arNull ? null : o.getAllottedResource().getSubcategory());
            put(valueMap, "ALLOTTED_RESOURCE_ROLE", o.getTargetNetworkRole() != null ? o.getTargetNetworkRole() : o.getNfRole());
            put(valueMap, "NF_TYPE", o.getNfType());
            put(valueMap, "NF_ROLE", o.getNfRole());
            put(valueMap, "NF_FUNCTION", o.getNfFunction());
            put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
            put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID());
            put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID());
            put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName());
            if (isJSONValid(o.getResourceInput())) {
                put(valueMap, "RESOURCE_INPUT", o.getResourceInput());
            }
            sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
            sep = ",\n";
        }
    }
    if (!first)
        sb.append("\n");
    if (isArray)
        sb.append("]");
    if (!isEmbed && isArray)
        sb.append("}");
    return sb.toString();
}
Also used : HashMap(java.util.HashMap) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization)

Example 5 with AllottedResourceCustomization

use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.

the class QueryAllottedResourceCustomization method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    int i = 1;
    for (AllottedResourceCustomization o : allottedResourceCustomization) {
        sb.append(i).append("\t");
        if (!first)
            sb.append("\n");
        first = false;
        sb.append(o);
    }
    return sb.toString();
}
Also used : AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization)

Aggregations

AllottedResourceCustomization (org.onap.so.db.catalog.beans.AllottedResourceCustomization)8 AllottedResource (org.onap.so.db.catalog.beans.AllottedResource)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)2 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)2 Service (org.onap.so.db.catalog.beans.Service)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Transactional (javax.transaction.Transactional)1 EntityQuery (org.onap.sdc.tosca.parser.elements.queries.EntityQuery)1 TopologyTemplateQuery (org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery)1 SdcCsarHelperImpl (org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl)1 CapabilityAssignment (org.onap.sdc.toscaparser.api.CapabilityAssignment)1 NodeTemplate (org.onap.sdc.toscaparser.api.NodeTemplate)1 CatalogQueryException (org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)1 QueryAllottedResourceCustomization (org.onap.so.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization)1 BaseTest (org.onap.so.asdc.BaseTest)1