Search in sources :

Example 6 with CloudSite

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;
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Quantum(com.woorea.openstack.quantum.Quantum) MsoException(org.onap.so.openstack.exceptions.MsoException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) CloudSite(org.onap.so.db.catalog.beans.CloudSite) Network(com.woorea.openstack.quantum.model.Network)

Example 7 with CloudSite

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());
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 8 with CloudSite

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();
    }
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite)

Example 9 with CloudSite

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));
}
Also used : Heat(com.woorea.openstack.heat.Heat) CloudSite(org.onap.so.db.catalog.beans.CloudSite) OpenStackRequest(com.woorea.openstack.base.client.OpenStackRequest) File(java.io.File) StackInfo(org.onap.so.openstack.beans.StackInfo) Stack(com.woorea.openstack.heat.model.Stack) Test(org.junit.Test)

Example 10 with CloudSite

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");
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Aggregations

CloudSite (org.onap.so.db.catalog.beans.CloudSite)54 Test (org.junit.Test)25 MsoCloudSiteNotFound (org.onap.so.openstack.exceptions.MsoCloudSiteNotFound)13 CloudIdentity (org.onap.so.db.catalog.beans.CloudIdentity)12 MsoException (org.onap.so.openstack.exceptions.MsoException)12 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)9 StackInfo (org.onap.so.openstack.beans.StackInfo)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 BaseTest (org.onap.so.BaseTest)7 CatalogDbAdapterBaseTest (org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)6 Keystone (com.woorea.openstack.keystone.Keystone)5 Quantum (com.woorea.openstack.quantum.Quantum)5 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)5 OpenStackRequest (com.woorea.openstack.base.client.OpenStackRequest)4 Heat (com.woorea.openstack.heat.Heat)4 Tenant (com.woorea.openstack.keystone.model.Tenant)4 Network (com.woorea.openstack.quantum.model.Network)4 MsoTenant (org.onap.so.openstack.beans.MsoTenant)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)3