use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class MsoNeutronUtils method deleteNetwork.
/**
* Delete the specified Network (by ID) in the given cloud. If the network does not exist, success is returned.
* <p>
*
* @param networkId Openstack ID of the network to delete
* @param tenantId The Openstack tenant.
* @param cloudSiteId The cloud identifier (may be a region) from which to delete the network.
* @return true if the network was deleted, false if the network did not exist
* @throws MsoOpenstackException If the Openstack API call returns an exception, this local exception will be
* thrown.
* @throws MsoCloudSiteNotFound
*/
public boolean deleteNetwork(String networkId, String tenantId, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will create the stack
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
Quantum neutronClient = getNeutronClient(cloudSite, tenantId);
try {
// Check that the network exists.
Network network = findNetworkById(neutronClient, networkId);
if (network == null) {
logger.info("{} Network not found! Network id: {} Cloud site: {} Tenant: {} ", MessageEnum.RA_DELETE_NETWORK_EXC, networkId, cloudSiteId, tenantId);
return false;
}
OpenStackRequest<Void> request = neutronClient.networks().delete(network.getId());
executeAndRecordOpenstackRequest(request);
logger.debug("Deleted Network {} ({})", network.getId(), network.getName());
} catch (OpenStackBaseException e) {
// Convert Neutron exception to an MsoOpenstackException
MsoException me = neutronExceptionToMsoException(e, "Delete Network");
throw me;
} catch (RuntimeException e) {
// Catch-all
MsoException me = runtimeExceptionToMsoException(e, "DeleteNetwork");
throw me;
}
return true;
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class CloudConfigTest method testGetDefaultCloudSite.
/**
* This method implements a test for the getCloudSite method.
*/
@Test
public final void testGetDefaultCloudSite() {
Optional<CloudSite> site = con.getCloudSite("NotThere");
assertTrue(site.isPresent());
CloudSite site1 = site.get();
assertEquals("NotThere", site1.getRegionId());
assertEquals("MDT13", site1.getClli());
assertEquals("NotThere", site1.getId());
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class CloudConfig method getDefaultCloudSite.
private Optional<CloudSite> getDefaultCloudSite(String clli) {
Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(catalogDbClient.getCloudSite(DEFAULT_CLOUD_SITE_ID));
if (cloudSiteOpt.isPresent()) {
CloudSite defaultCloudSite = cloudSiteOpt.get();
CloudSite clone = new CloudSite(defaultCloudSite);
clone.setRegionId(clli);
clone.setId(clli);
return Optional.of(clone);
} else {
return Optional.empty();
}
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class MsoHeatUtilsWithUpdateTest method updateStackWithEnvironmentTest.
@Test
public void updateStackWithEnvironmentTest() throws JsonParseException, JsonMappingException, IOException, MsoException {
String environmentString = "environmentString";
CloudSite cloudSite = new CloudSite();
Heat heatClient = new Heat("endpoint");
Stack heatStack = mapper.readValue(new File(RESOURCE_PATH + "HeatStack.json"), Stack.class);
Stack updateStack = mapper.readValue(new File(RESOURCE_PATH + "UpdateStack.json"), Stack.class);
StackInfo expectedStackInfo = new StackInfo("stackName", HeatStatus.UPDATED, "stackStatusReason", null);
expectedStackInfo.setCanonicalName("stackName/id");
doReturn(heatClient).when(heatUtils).getHeatClient(isA(String.class), isA(String.class));
doReturn(null).when(heatUtils).executeAndRecordOpenstackRequest(isA(OpenStackRequest.class));
doReturn("0").when(environment).getProperty(isA(String.class), isA(String.class));
doReturn(updateStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class));
StackInfo actualStackInfo = heatUtils.updateStack(cloudSiteId, cloudOwner, tenantId, stackName, heatTemplate, stackInputs, pollForCompletion, timeoutMinutes, environmentString);
assertThat(actualStackInfo, sameBeanAs(expectedStackInfo));
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class MsoHeatUtilsITTest method getHeatClientOpenStackResponseException404Test.
@Test(expected = MsoOpenstackException.class)
public final void getHeatClientOpenStackResponseException404Test() throws MsoException, IOException {
CloudSite cloudSite = getCloudSite(getCloudIdentity());
// mo mocks setup will cause 404 response from wiremock
heatUtils.getHeatClient("MTN13", "TEST-tenant");
}
Aggregations