Search in sources :

Example 1 with InstanceResponse

use of org.onap.so.client.adapter.cnf.entities.InstanceResponse in project so by onap.

the class CnfAdapterCreateTasks method createInstance.

/**
 * This method is used for creating the request for an Instance in Multicloud K8s Plugin.
 *
 * @param execution
 * @return
 */
public void createInstance(BuildingBlockExecution execution) {
    try {
        GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
        ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
        GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
        VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
        RequestContext requestContext = gBBInput.getRequestContext();
        CloudRegion cloudRegion = gBBInput.getCloudRegion();
        String sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId());
        String sdncVnfQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId());
        Map<String, Object> paramsMap = vfModuleMapper.buildVfModuleParamsMap(requestContext, serviceInstance, genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
        Map<String, String> sdncDirectives = getSdncDirectives(paramsMap);
        InstanceRequest createInstanceRequest = createInstanceRequest(vfModule, cloudRegion, sdncDirectives);
        InstanceResponse response = cnfAdapterClient.createVfModule(createInstanceRequest);
        execution.setVariable("heatStackId", response.getId());
    } catch (Exception ex) {
        logger.error("Exception occurred", ex);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) InstanceResponse(org.onap.so.client.adapter.cnf.entities.InstanceResponse) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) InstanceRequest(org.onap.so.client.adapter.cnf.entities.InstanceRequest)

Example 2 with InstanceResponse

use of org.onap.so.client.adapter.cnf.entities.InstanceResponse in project so by onap.

the class CnfAdapterClient method createVfModule.

@Retryable(value = { HttpServerErrorException.class }, maxAttempts = 3, backoff = @Backoff(delay = 3000))
public InstanceResponse createVfModule(InstanceRequest request) throws CnfAdapterClientException {
    try {
        // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
        // for configuration
        String uri = "http://so-cnf-adapter:8090";
        String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH).build().toString();
        HttpEntity<?> entity = getHttpEntity(request);
        ResponseEntity<InstanceResponse> result = restTemplate.exchange(endpoint, HttpMethod.POST, entity, InstanceResponse.class);
        return result.getBody();
    } catch (HttpClientErrorException e) {
        logger.error("Error Calling CNF Adapter, e");
        if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
            throw new EntityNotFoundException(e.getResponseBodyAsString());
        }
        throw e;
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) UpgradeInstanceResponse(org.onap.so.client.adapter.cnf.entities.UpgradeInstanceResponse) InstanceResponse(org.onap.so.client.adapter.cnf.entities.InstanceResponse) EntityNotFoundException(javax.persistence.EntityNotFoundException) Retryable(org.springframework.retry.annotation.Retryable)

Example 3 with InstanceResponse

use of org.onap.so.client.adapter.cnf.entities.InstanceResponse in project so by onap.

the class CnfAdapterClient method healthcheck.

@Retryable(value = { HttpServerErrorException.class }, maxAttempts = 3, backoff = @Backoff(delay = 3000))
public InstanceResponse healthcheck() throws CnfAdapterClientException {
    try {
        // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well
        // for configuration
        String uri = "http://so-cnf-adapter:8090";
        String endpoint = UriBuilder.fromUri(uri).path("/api/cnf-adapter/v1/healthcheck").build().toString();
        HttpEntity<?> entity = new HttpEntity<>(getHttpHeaders());
        ResponseEntity<InstanceResponse> result = restTemplate.exchange(endpoint, HttpMethod.GET, entity, InstanceResponse.class);
        return result.getBody();
    } catch (HttpClientErrorException e) {
        logger.error("Error Calling CNF Adapter, e");
        if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
            throw new EntityNotFoundException(e.getResponseBodyAsString());
        }
        throw e;
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) UpgradeInstanceResponse(org.onap.so.client.adapter.cnf.entities.UpgradeInstanceResponse) InstanceResponse(org.onap.so.client.adapter.cnf.entities.InstanceResponse) EntityNotFoundException(javax.persistence.EntityNotFoundException) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

InstanceResponse (org.onap.so.client.adapter.cnf.entities.InstanceResponse)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)2 UpgradeInstanceResponse (org.onap.so.client.adapter.cnf.entities.UpgradeInstanceResponse)2 Retryable (org.springframework.retry.annotation.Retryable)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 CloudRegion (org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion)1 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)1 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)1 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)1 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)1 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)1 InstanceRequest (org.onap.so.client.adapter.cnf.entities.InstanceRequest)1 HttpEntity (org.springframework.http.HttpEntity)1