Search in sources :

Example 11 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class MsoMulticloudUtils method multicloudAaiUpdate.

private void multicloudAaiUpdate(String cloudSiteId, String cloudOwner, String tenantId, String genericVnfId, String vfModuleId, String workloadId, boolean pollForCompletion, int timeoutMinutes) {
    String stackId = null;
    int offset = workloadId.indexOf('/');
    if (offset > 0 && offset < (workloadId.length() - 1)) {
        stackId = workloadId.substring(offset + 1);
    } else {
        stackId = workloadId;
    }
    MulticloudRequest multicloudRequest = new MulticloudRequest();
    multicloudRequest.setGenericVnfId(genericVnfId);
    multicloudRequest.setVfModuleId(vfModuleId);
    String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId, false);
    RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);
    if (multicloudClient == null) {
        if (logger.isDebugEnabled())
            logger.debug("Multicloud client could not be initialized");
        return;
    }
    Response response = multicloudClient.post(multicloudRequest);
    if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
        if (logger.isDebugEnabled())
            logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), response.getStatusInfo());
        return;
    }
    if (!pollForCompletion) {
        return;
    }
    int updatePollInterval = Integer.parseInt(this.environment.getProperty(createPollIntervalProp, CREATE_POLL_INTERVAL_DEFAULT));
    int pollTimeout = (timeoutMinutes * 60) + updatePollInterval;
    boolean updateTimedOut = false;
    logger.debug("updatePollInterval={}, pollTimeout={}", updatePollInterval, pollTimeout);
    StackInfo stackInfo = null;
    while (true) {
        try {
            stackInfo = queryStack(cloudSiteId, cloudOwner, tenantId, workloadId);
            if (logger.isDebugEnabled())
                logger.debug("{} ({})", stackInfo.getStatus(), workloadId);
            if (HeatStatus.UPDATING.equals(stackInfo.getStatus())) {
                if (pollTimeout <= 0) {
                    // in the Openstack (multicloud?) call.
                    if (logger.isDebugEnabled())
                        logger.debug("Multicloud AAI update timeout failure: {} {} {} {}", cloudOwner, cloudSiteId, tenantId, workloadId);
                    updateTimedOut = true;
                    break;
                }
                sleep(updatePollInterval * 1000L);
                pollTimeout -= updatePollInterval;
                if (logger.isDebugEnabled())
                    logger.debug("pollTimeout remaining: {}", pollTimeout);
            } else {
                break;
            }
        } catch (MsoException me) {
            if (logger.isDebugEnabled())
                logger.debug("Multicloud AAI update exception: {} {} {} {}", cloudOwner, cloudSiteId, tenantId, workloadId, me);
            return;
        }
    }
    if (updateTimedOut) {
        if (logger.isDebugEnabled())
            logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), response.getStatusInfo());
    } else if (!HeatStatus.UPDATED.equals(stackInfo.getStatus())) {
        if (logger.isDebugEnabled())
            logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), response.getStatusInfo());
    } else {
        if (logger.isDebugEnabled())
            logger.debug("Multicloud AAI update successful: {} {}", response.getStatus(), response.getStatusInfo());
    }
}
Also used : Response(javax.ws.rs.core.Response) MsoException(org.onap.so.openstack.exceptions.MsoException) RestClient(org.onap.so.client.RestClient) StackInfo(org.onap.so.openstack.beans.StackInfo)

Example 12 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIResourcesClientTest method testGetOne.

@Test
public void testGetOne() {
    GenericVnf vnf = new GenericVnf();
    vnf.setVnfId("my-vnf-id");
    GenericVnfs vnfs = new GenericVnfs();
    vnfs.getGenericVnf().add(vnf);
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
    RestClient restClientMock = mock(RestClient.class);
    doReturn(restClientMock).when(client).createClient(uri);
    when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
    Optional<GenericVnf> result = aaiClient.getOne(GenericVnfs.class, GenericVnf.class, uri);
    assertEquals("my-vnf-id", result.get().getVnfId());
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs) RestClient(org.onap.so.client.RestClient) Test(org.junit.Test)

Example 13 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIResourcesClientTest method testGetFirstNoResults.

@Test
public void testGetFirstNoResults() {
    GenericVnf vnf = new GenericVnf();
    vnf.setVnfId("my-vnf-id");
    GenericVnfs vnfs = new GenericVnfs();
    vnfs.getGenericVnf().add(vnf);
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
    RestClient restClientMock = mock(RestClient.class);
    doReturn(restClientMock).when(client).createClient(uri);
    when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.empty());
    Optional<GenericVnf> result = aaiClient.getFirst(GenericVnfs.class, GenericVnf.class, uri);
    assertFalse(result.isPresent());
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs) RestClient(org.onap.so.client.RestClient) Test(org.junit.Test)

Example 14 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIResourcesClientTest method testGetOneMultipleResults.

@Test
public void testGetOneMultipleResults() {
    GenericVnf vnf = new GenericVnf();
    vnf.setVnfId("my-vnf-id");
    GenericVnf vnf2 = new GenericVnf();
    vnf.setVnfId("my-vnf-id2");
    GenericVnfs vnfs = new GenericVnfs();
    vnfs.getGenericVnf().add(vnf);
    vnfs.getGenericVnf().add(vnf2);
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
    RestClient restClientMock = mock(RestClient.class);
    doReturn(restClientMock).when(client).createClient(uri);
    when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
    thrown.expect(GraphInventoryMultipleItemsException.class);
    aaiClient.getOne(GenericVnfs.class, GenericVnf.class, uri);
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs) RestClient(org.onap.so.client.RestClient) Test(org.junit.Test)

Example 15 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIRestClientTest method cachePutTest.

@Test
public void cachePutTest() throws URISyntaxException, InterruptedException {
    wireMockRule.stubFor(put(urlPathMatching("/cached/1")).willReturn(aResponse().withStatus(200)));
    wireMockRule.stubFor(get(urlPathMatching("/cached/1")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("{}")));
    AAIProperties props = new AAIProperties() {

        @Override
        public URL getEndpoint() throws MalformedURLException {
            return new URL(String.format("http://localhost:%s", wireMockRule.port()));
        }

        @Override
        public String getSystemName() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isCachingEnabled() {
            return true;
        }

        @Override
        public AAIVersion getDefaultVersion() {
            return AAIVersion.LATEST;
        }

        @Override
        public String getAuth() {
            return null;
        }

        @Override
        public String getKey() {
            return null;
        }
    };
    RestClient client = new AAIRestClient(props, new URI("/cached/1"), new MultivaluedHashMap<>());
    Response response = client.get();
    response.readEntity(String.class);
    client.put("wow");
    client.get();
    response.readEntity(String.class);
    verify(2, getRequestedFor(urlEqualTo("/cached/1")));
}
Also used : WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Response(javax.ws.rs.core.Response) RestClient(org.onap.so.client.RestClient) URI(java.net.URI) URL(java.net.URL) Test(org.junit.Test)

Aggregations

RestClient (org.onap.so.client.RestClient)23 Test (org.junit.Test)8 Response (javax.ws.rs.core.Response)7 GenericVnf (org.onap.aai.domain.yang.GenericVnf)6 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)6 GenericVnfs (org.onap.aai.domain.yang.GenericVnfs)5 StackInfo (org.onap.so.openstack.beans.StackInfo)4 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)2 URI (java.net.URI)2 URL (java.net.URL)2 NotFoundException (javax.ws.rs.NotFoundException)2 BulkProcessFailed (org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)2 CreateStackParam (com.woorea.openstack.heat.model.CreateStackParam)1 Stack (com.woorea.openstack.heat.model.Stack)1 Map (java.util.Map)1 GenericType (javax.ws.rs.core.GenericType)1 SingleTransactionResponse (org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse)1 GraphInventoryPluralResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryPluralResourceUri)1 GraphInventoryResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryResourceUri)1 GraphInventorySingleResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventorySingleResourceUri)1