Search in sources :

Example 71 with AAIResultWrapper

use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.

the class AppcRunTasksTest method getVserversForAppcTest.

@Test
public void getVserversForAppcTest() throws Exception {
    GenericVnf genericVnf = getTestGenericVnf();
    final String aaiVnfJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json")));
    final String aaiVserverJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json")));
    AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiVnfJson);
    ObjectMapper mapper = new ObjectMapper();
    Vserver vserver = mapper.readValue(aaiVserverJson, Vserver.class);
    doReturn(aaiResultWrapper).when(aaiVnfResources).queryVnfWrapperById(genericVnf);
    doReturn(Optional.of(vserver)).when(aaiVnfResources).getVserver(any(AAIResourceUri.class));
    appcRunTasks.getVserversForAppc(execution, genericVnf);
    String vserverIdList = execution.getVariable("vserverIdList");
    String expectedVserverIdList = "{\"vserverIds\":\"[\\\"1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5\\\",\\\"14551849-1e70-45cd-bc5d-a256d49548a2\\\",\\\"48bd7f11-408f-417c-b834-b41c1b98f7d7\\\"]\"}";
    String vmIdList = execution.getVariable("vmIdList");
    String expectedVmIdList = "{\"vmIds\":\"[\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\"]\"}";
    assertEquals(vserverIdList, expectedVserverIdList);
    assertEquals(vmIdList, expectedVmIdList);
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Example 72 with AAIResultWrapper

use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.

the class WorkflowAction method getRelatedResourcesInVfModule.

protected <T> List<T> getRelatedResourcesInVfModule(String vnfId, String vfModuleId, Class<T> resultClass, AAIObjectName name) {
    List<T> vnfcs = new ArrayList<>();
    AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId));
    AAIResultWrapper vfModuleResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri);
    Optional<Relationships> relationshipsOp = vfModuleResultsWrapper.getRelationships();
    if (relationshipsOp.isEmpty()) {
        logger.debug("No relationships were found for vfModule in AAI");
    } else {
        Relationships relationships = relationshipsOp.get();
        List<AAIResultWrapper> vnfcResultWrappers = relationships.getByType(name);
        for (AAIResultWrapper vnfcResultWrapper : vnfcResultWrappers) {
            Optional<T> vnfcOp = vnfcResultWrapper.asBean(resultClass);
            vnfcOp.ifPresent(vnfcs::add);
        }
    }
    return vnfcs;
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 73 with AAIResultWrapper

use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.

the class ServiceEBBLoader method getExistingAAIVrfConfiguration.

protected String getExistingAAIVrfConfiguration(RelatedInstance relatedVpnBinding, org.onap.aai.domain.yang.L3Network aaiLocalNetwork) throws JsonProcessingException, VrfBondingServiceException {
    Optional<Relationships> relationshipsOp = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiLocalNetwork)).getRelationships();
    if (relationshipsOp.isPresent()) {
        List<AAIResultWrapper> configurationsRelatedToLocalNetwork = relationshipsOp.get().getByType(AAIFluentTypeBuilder.Types.CONFIGURATION);
        if (configurationsRelatedToLocalNetwork.size() > 1) {
            throw new VrfBondingServiceException("Network: " + aaiLocalNetwork.getNetworkId() + " has more than 1 configuration related to it");
        }
        if (configurationsRelatedToLocalNetwork.size() == 1) {
            AAIResultWrapper configWrapper = configurationsRelatedToLocalNetwork.get(0);
            Optional<Configuration> relatedConfiguration = configWrapper.asBean(Configuration.class);
            if (relatedConfiguration.isPresent() && vrfConfigurationAlreadyExists(relatedVpnBinding, relatedConfiguration.get(), configWrapper)) {
                return relatedConfiguration.get().getConfigurationId();
            }
        }
    }
    return null;
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Configuration(org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) VrfBondingServiceException(org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 74 with AAIResultWrapper

use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.

the class VnfEBBLoader method findConfigurationsInsideVfModule.

private void findConfigurationsInsideVfModule(DelegateExecution execution, org.onap.aai.domain.yang.VfModule aaiVfModule, List<Resource> resourceList, Resource vfModuleResource, List<Pair<WorkflowType, String>> aaiResourceIds) {
    try {
        AAIResultWrapper vfModuleWrapper = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule));
        Optional<Relationships> relationshipsOp;
        relationshipsOp = vfModuleWrapper.getRelationships();
        if (relationshipsOp.isPresent()) {
            relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get());
            addConfigToResources(relationshipsOp, resourceList, vfModuleResource, aaiResourceIds);
        }
    } catch (Exception ex) {
        logger.error("Exception in findConfigurationsInsideVfModule", ex);
        buildAndThrowException(execution, "Failed to find Configuration object from the vfModule.");
    }
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 75 with AAIResultWrapper

use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.

the class CreateVnfOperationalEnvironment method execute.

public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    try {
        setRequest(request);
        ObjectMapper objectMapper = new ObjectMapper();
        AAIResultWrapper aaiResultWrapper = aaiHelper.getAaiOperationalEnvironment(getEcompManagingEnvironmentId());
        if (aaiResultWrapper.isEmpty()) {
            throw new NotFoundException(getEcompManagingEnvironmentId() + " not found in A&AI");
        }
        OperationalEnvironment aaiEnv = aaiResultWrapper.asBean(OperationalEnvironment.class).get();
        // Find ECOMP environments in GRM
        logger.debug(" Start of GRM findRunningServicesAsString");
        String searchKey = getSearchKey(aaiEnv);
        String tenantContext = getTenantContext().toUpperCase();
        String jsonResponse = getGrmClient().findRunningServicesAsString(searchKey, 1, tenantContext);
        ServiceEndPointList sel = objectMapper.readValue(jsonResponse, ServiceEndPointList.class);
        if (sel.getServiceEndPointList().size() == 0) {
            throw new TenantIsolationException("GRM did not find any matches for " + searchKey + " in " + tenantContext);
        }
        // Replicate end-point for VNF Operating environment in GRM
        List<ServiceEndPointRequest> serviceEndpointRequestList = buildEndPointRequestList(sel);
        int ctr = 0;
        int total = serviceEndpointRequestList.size();
        for (ServiceEndPointRequest requestList : serviceEndpointRequestList) {
            logger.debug("Creating endpoint " + ++ctr + " of " + total + ": " + requestList.getServiceEndPoint().getName());
            getGrmClient().addServiceEndPoint(requestList);
        }
        // Create VNF operating in A&AI
        aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("INACTIVE", request));
        aaiHelper.createRelationship(request.getOperationalEnvironmentId(), getEcompManagingEnvironmentId());
        // Update request database
        requestDb.updateInfraSuccessCompletion("SUCCESSFULLY created VNF operational environment", requestId, request.getOperationalEnvironmentId());
    } catch (Exception e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
}
Also used : ServiceEndPointList(org.onap.so.client.grm.beans.ServiceEndPointList) ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) AAIClientObjectBuilder(org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder) NotFoundException(javax.ws.rs.NotFoundException) ServiceEndPoint(org.onap.so.client.grm.beans.ServiceEndPoint) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) NotFoundException(javax.ws.rs.NotFoundException) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Aggregations

AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)88 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)47 Test (org.junit.Test)46 Relationships (org.onap.aaiclient.client.aai.entities.Relationships)27 ArrayList (java.util.ArrayList)22 AAICommonObjectMapperProvider (org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider)22 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)14 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)11 VpnBinding (org.onap.aai.domain.yang.VpnBinding)7 CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 HashMap (java.util.HashMap)6 OperationalEnvironment (org.onap.aai.domain.yang.OperationalEnvironment)6 RelationshipList (org.onap.aai.domain.yang.RelationshipList)6 AAIResourcesClient (org.onap.aaiclient.client.aai.AAIResourcesClient)6 List (java.util.List)5 Optional (java.util.Optional)5 AAIFluentTypeBuilder (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder)5 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)5 Map (java.util.Map)4