Search in sources :

Example 1 with ServiceEndPointRequest

use of org.onap.so.client.grm.beans.ServiceEndPointRequest in project so by onap.

the class ServiceEndPointRequestTest method testMarshall.

@Test
public void testMarshall() throws Exception {
    String expected = "{\"serviceEndPoint\":{\"name\":\"TEST.ECOMP_PSL.Inventory\",\"version\":{\"major\":1,\"minor\":0,\"patch\":\"0\"}," + "\"hostAddress\":\"127.0.0.1\",\"listenPort\":\"8080\",\"latitude\":\"37.7022\",\"longitude\":\"121.9358\"," + "\"contextPath\":\"/\",\"routeOffer\":\"TEST\",\"operationalInfo\":{\"createdBy\":\"edge\",\"updatedBy\":\"edge\"}," + "\"properties\":[{\"name\":\"Environment\",\"value\":\"TEST\"},{\"name\":\"cpfrun_cluster_name\"," + "\"value\":\"testcase_cluster_no_cluster\"}]},\"env\":\"DEV\"}";
    Version ver = new Version();
    ver.setMajor(1);
    ver.setMinor(0);
    ver.setPatch("0");
    ServiceEndPoint sep = new ServiceEndPoint();
    sep.setName("TEST.ECOMP_PSL.Inventory");
    sep.setVersion(ver);
    sep.setHostAddress("127.0.0.1");
    sep.setListenPort("8080");
    sep.setLatitude("37.7022");
    sep.setLongitude("121.9358");
    sep.setContextPath("/");
    sep.setRouteOffer("TEST");
    OperationalInfo operInfo = new OperationalInfo();
    operInfo.setCreatedBy("edge");
    operInfo.setUpdatedBy("edge");
    sep.setOperationalInfo(operInfo);
    Property prop1 = new Property();
    prop1.setName("Environment");
    prop1.setValue("TEST");
    Property prop2 = new Property();
    prop2.setName("cpfrun_cluster_name");
    prop2.setValue("testcase_cluster_no_cluster");
    List<Property> props = new ArrayList<Property>();
    props.add(prop1);
    props.add(prop2);
    sep.setProperties(props);
    ServiceEndPointRequest request = new ServiceEndPointRequest();
    request.setEnv("DEV");
    request.setServiceEndPoint(sep);
    assertEquals(expected, mapper.writeValueAsString(request));
}
Also used : ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) Version(org.onap.so.client.grm.beans.Version) OperationalInfo(org.onap.so.client.grm.beans.OperationalInfo) ArrayList(java.util.ArrayList) ServiceEndPoint(org.onap.so.client.grm.beans.ServiceEndPoint) Property(org.onap.so.client.grm.beans.Property) Test(org.junit.Test)

Example 2 with ServiceEndPointRequest

use of org.onap.so.client.grm.beans.ServiceEndPointRequest in project so by onap.

the class CreateVnfOperationalEnvironment method buildEndPointRequestList.

private List<ServiceEndPointRequest> buildEndPointRequestList(ServiceEndPointList serviceEndPointList) throws TenantIsolationException {
    List<ServiceEndPoint> endpointList = serviceEndPointList.getServiceEndPointList();
    logger.debug("Number of service endpoints from GRM: {}", endpointList.size());
    List<ServiceEndPointRequest> serviceEndPointRequestList = new ArrayList<>();
    for (ServiceEndPoint serviceEndpoint : endpointList) {
        serviceEndPointRequestList.add(buildServiceEndpoint(serviceEndpoint));
    }
    return serviceEndPointRequestList;
}
Also used : ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) ArrayList(java.util.ArrayList) ServiceEndPoint(org.onap.so.client.grm.beans.ServiceEndPoint)

Example 3 with ServiceEndPointRequest

use of org.onap.so.client.grm.beans.ServiceEndPointRequest in project so by onap.

the class GRMClientTest method testAddFail.

@Test
public void testAddFail() throws Exception {
    wireMockServer.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")).willReturn(aResponse().withStatus(404).withHeader("Content-Type", MediaType.APPLICATION_JSON).withBody("test")));
    ServiceEndPointRequest request = new ServiceEndPointRequest();
    GRMClient client = new GRMClient();
    thrown.expect(GRMClientCallFailed.class);
    client.addServiceEndPoint(request);
}
Also used : ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 4 with ServiceEndPointRequest

use of org.onap.so.client.grm.beans.ServiceEndPointRequest 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)

Example 5 with ServiceEndPointRequest

use of org.onap.so.client.grm.beans.ServiceEndPointRequest in project so by onap.

the class CreateVnfOperationalEnvironment method buildServiceEndpoint.

private ServiceEndPointRequest buildServiceEndpoint(ServiceEndPoint serviceEndpoint) throws TenantIsolationException {
    // @TODO: handle nulls? Put in a ServiceEndpointWrapper class which will check for nulls and flatten access to
    // fields
    Version ver = new Version();
    ver.setMajor(serviceEndpoint.getVersion().getMajor());
    ver.setMinor(serviceEndpoint.getVersion().getMinor());
    ver.setPatch(serviceEndpoint.getVersion().getPatch());
    ServiceEndPoint endpoint = new ServiceEndPoint();
    endpoint.setName(buildServiceNameForVnf(serviceEndpoint.getName()));
    endpoint.setVersion(ver);
    endpoint.setHostAddress(serviceEndpoint.getHostAddress());
    endpoint.setListenPort(serviceEndpoint.getListenPort());
    endpoint.setLatitude(serviceEndpoint.getLatitude());
    endpoint.setLongitude(serviceEndpoint.getLongitude());
    endpoint.setContextPath(serviceEndpoint.getContextPath());
    endpoint.setRouteOffer(serviceEndpoint.getRouteOffer());
    OperationalInfo operInfo = new OperationalInfo();
    operInfo.setCreatedBy(serviceEndpoint.getOperationalInfo().getCreatedBy());
    operInfo.setUpdatedBy(serviceEndpoint.getOperationalInfo().getUpdatedBy());
    endpoint.setOperationalInfo(operInfo);
    endpoint.setProperties(serviceEndpoint.getProperties());
    String env = getEnvironmentName(serviceEndpoint.getProperties());
    ServiceEndPointRequest serviceEndPontRequest = new ServiceEndPointRequest();
    serviceEndPontRequest.setEnv(env);
    serviceEndPontRequest.setServiceEndPoint(endpoint);
    return serviceEndPontRequest;
}
Also used : ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) Version(org.onap.so.client.grm.beans.Version) OperationalInfo(org.onap.so.client.grm.beans.OperationalInfo) ServiceEndPoint(org.onap.so.client.grm.beans.ServiceEndPoint)

Aggregations

ServiceEndPointRequest (org.onap.so.client.grm.beans.ServiceEndPointRequest)5 ServiceEndPoint (org.onap.so.client.grm.beans.ServiceEndPoint)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 OperationalInfo (org.onap.so.client.grm.beans.OperationalInfo)2 Version (org.onap.so.client.grm.beans.Version)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 NotFoundException (javax.ws.rs.NotFoundException)1 OperationalEnvironment (org.onap.aai.domain.yang.OperationalEnvironment)1 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)1 BaseTest (org.onap.so.apihandlerinfra.BaseTest)1 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)1 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)1 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)1 TenantIsolationException (org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException)1 AAIClientObjectBuilder (org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder)1 Property (org.onap.so.client.grm.beans.Property)1 ServiceEndPointList (org.onap.so.client.grm.beans.ServiceEndPointList)1