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());
}
}
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());
}
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());
}
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);
}
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")));
}
Aggregations