Search in sources :

Example 6 with MsoCloudSiteNotFound

use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.

the class MsoTenantUtilsFactoryTest method getTenantUtils_shouldThrowException_whenNoCloudSiteFoundForGivenId.

@Test
public void getTenantUtils_shouldThrowException_whenNoCloudSiteFoundForGivenId() {
    // GIVEN
    String cloudSiteId = "CloudSiteId";
    given(cloudConfig.getCloudSite(cloudSiteId)).willReturn(Optional.empty());
    // WHEN
    MsoCloudSiteNotFound msoCloudSiteNotFound = catchThrowableOfType(() -> msoTenantUtilsFactory.getTenantUtils(cloudSiteId), MsoCloudSiteNotFound.class);
    // THEN
    assertThat(msoCloudSiteNotFound.getMessage()).contains(cloudSiteId);
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Test(org.junit.Test)

Example 7 with MsoCloudSiteNotFound

use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.

the class CreateAAIInventory method heatbridge.

public void heatbridge(CloudInformation cloudInformation) throws HeatBridgeException, MsoCloudSiteNotFound {
    CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId()).orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
    if (cloudSite.getOrchestrator() != null && MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.getOrchestrator())) {
        logger.debug("Skipping Heatbridge as CloudSite orchestrator is: " + MULTICLOUD_MODE);
        return;
    }
    CloudIdentity cloudIdentity = cloudSite.getIdentityService();
    String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
    List<String> oobMgtNetNames = new ArrayList<>();
    HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
    heatBridgeClient.authenticate();
    List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId());
    List<Network> osNetworks = heatBridgeClient.getAllOpenstackProviderNetworks(stackResources);
    heatBridgeClient.buildAddNetworksToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osNetworks);
    List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
    heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
    List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
    List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
    logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
    // os images
    if (osImages != null && !osImages.isEmpty()) {
        heatBridgeClient.buildAddImagesToAaiAction(osImages);
        logger.debug("Successfully built AAI actions to add images.");
    } else {
        logger.debug("No images to update to AAI.");
    }
    // flavors
    if (osFlavors != null && !osFlavors.isEmpty()) {
        heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
        logger.debug("Successfully built AAI actions to add flavors.");
    } else {
        logger.debug("No flavors to update to AAI.");
    }
    // compute resources
    heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osServers);
    logger.debug("Successfully queried compute resources and built AAI vserver actions.");
    // neutron resources
    List<String> oobMgtNetIds = new ArrayList<>();
    // if no network-id list is provided, however network-name list is
    if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
        oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
    }
    heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds, cloudInformation.getOwner());
    logger.debug("Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
    heatBridgeClient.buildAddVolumes(stackResources);
    // Update AAI
    logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
    heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Server(org.openstack4j.model.compute.Server) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) ArrayList(java.util.ArrayList) Resource(org.openstack4j.model.heat.Resource) Image(org.openstack4j.model.compute.Image) Flavor(org.openstack4j.model.compute.Flavor) CloudSite(org.onap.so.db.catalog.beans.CloudSite) HeatBridgeApi(org.onap.so.heatbridge.HeatBridgeApi) Network(org.openstack4j.model.network.Network)

Example 8 with MsoCloudSiteNotFound

use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.

the class MsoCommonUtils method getKeystoneAuthHolder.

/**
 * Gets the Keystone Authorization
 *
 * @param cloudSite the cloud site
 * @param tenantId the tenant id
 * @return the Neutron client
 * @throws MsoException the mso exception
 */
protected KeystoneAuthHolder getKeystoneAuthHolder(String cloudSiteId, String tenantId, String serviceName) throws MsoException {
    CloudIdentity cloudIdentity = null;
    try {
        CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
        String cloudId = cloudSite.getId();
        String region = cloudSite.getRegionId();
        cloudIdentity = cloudSite.getIdentityService();
        MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
        String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
        if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
            Access access = getKeystone(tenantId, cloudIdentity, keystoneUrl);
            try {
                KeystoneAuthHolder keystoneAuthV2 = new KeystoneAuthHolder();
                keystoneAuthV2.setServiceUrl(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), serviceName, region, "public"));
                keystoneAuthV2.setId(access.getToken().getId());
                return keystoneAuthV2;
            } catch (RuntimeException e) {
                String error = "Openstack did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
                throw new MsoAdapterException(error, e);
            }
        } else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
            try {
                return keystoneV3Authentication.getToken(cloudSite, tenantId, serviceName);
            } catch (ServiceEndpointNotFoundException e) {
                String error = "cloud did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
                throw new MsoAdapterException(error, e);
            }
        } else {
            throw new MsoAdapterException("Unknown Keystone Server Type");
        }
    } catch (OpenStackResponseException e) {
        if (e.getStatus() == 401) {
            String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId();
            throw new MsoAdapterException(error);
        } else {
            throw keystoneErrorToMsoException(e, TOKEN_AUTH);
        }
    } catch (OpenStackConnectException e) {
        MsoIOException me = new MsoIOException(e.getMessage(), e);
        me.addContext(TOKEN_AUTH);
        throw me;
    } catch (RuntimeException e) {
        throw runtimeExceptionToMsoException(e, TOKEN_AUTH);
    }
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) Access(com.woorea.openstack.keystone.model.Access) KeystoneAuthHolder(org.onap.so.cloud.authentication.KeystoneAuthHolder) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ServiceEndpointNotFoundException(org.onap.so.cloud.authentication.ServiceEndpointNotFoundException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) CloudSite(org.onap.so.db.catalog.beans.CloudSite) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 9 with MsoCloudSiteNotFound

use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.

the class MsoKeystoneUtils method deleteTenant.

/**
 * Delete the specified Tenant (by ID) in the given cloud. This method returns true or false, depending on whether
 * the tenant existed and was successfully deleted, or if the tenant already did not exist. Both cases are treated
 * as success (no Exceptions).
 * <p>
 * Note for the AIC Cloud (DCP/LCP): all admin requests go to the centralized identity service in DCP. So deleting a
 * tenant from one cloudSiteId will remove it from all sites managed by that identity service.
 * <p>
 *
 * @param tenantId The Openstack ID of the tenant to delete
 * @param cloudSiteId The cloud identifier from which to delete the tenant.
 * @return true if the tenant was deleted, false if the tenant did not exist.
 * @throws MsoOpenstackException If the Openstack API call returns an exception.
 */
public boolean deleteTenant(String tenantId, String cloudSiteId) throws MsoException {
    // Obtain the cloud site information where we will query the tenant
    CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
    Keystone keystoneAdminClient = getKeystoneAdminClient(cloudSite);
    try {
        // Check that the tenant exists. Also, need the ID to delete
        Tenant tenant = findTenantById(keystoneAdminClient, tenantId);
        if (tenant == null) {
            LOGGER.error("{} Tenant id {} not found on cloud site id {}, {}", MessageEnum.RA_TENANT_NOT_FOUND, tenantId, cloudSiteId, ErrorCode.DataError.getValue());
            return false;
        }
        OpenStackRequest<Void> request = keystoneAdminClient.tenants().delete(tenant.getId());
        executeAndRecordOpenstackRequest(request);
        LOGGER.debug("Deleted Tenant {} ({})", tenant.getId(), tenant.getName());
    } catch (OpenStackBaseException e) {
        // Convert Keystone OpenStackResponseException to MsoOpenstackException
        throw keystoneErrorToMsoException(e, DELETE_TENANT);
    } catch (RuntimeException e) {
        // Catch-all
        throw runtimeExceptionToMsoException(e, DELETE_TENANT);
    }
    return true;
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) MsoTenant(org.onap.so.openstack.beans.MsoTenant) Tenant(com.woorea.openstack.keystone.model.Tenant) Keystone(com.woorea.openstack.keystone.Keystone) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) CloudSite(org.onap.so.db.catalog.beans.CloudSite)

Example 10 with MsoCloudSiteNotFound

use of org.onap.so.openstack.exceptions.MsoCloudSiteNotFound in project so by onap.

the class MsoNeutronUtils method getNeutronPort.

public Optional<Port> getNeutronPort(String neutronPortId, String tenantId, String cloudSiteId) {
    try {
        logger.debug("Finding Neutron port:" + neutronPortId);
        CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
        Quantum neutronClient = getNeutronClient(cloudSite, tenantId);
        Port port = findPortById(neutronClient, neutronPortId);
        if (port == null) {
            return Optional.empty();
        }
        return Optional.of(port);
    } catch (RuntimeException | MsoException e) {
        logger.error("Error retrieving neutron port", e);
        return Optional.empty();
    }
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Quantum(com.woorea.openstack.quantum.Quantum) MsoException(org.onap.so.openstack.exceptions.MsoException) CloudSite(org.onap.so.db.catalog.beans.CloudSite) Port(com.woorea.openstack.quantum.model.Port)

Aggregations

MsoCloudSiteNotFound (org.onap.so.openstack.exceptions.MsoCloudSiteNotFound)14 CloudSite (org.onap.so.db.catalog.beans.CloudSite)13 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)9 MsoException (org.onap.so.openstack.exceptions.MsoException)6 Keystone (com.woorea.openstack.keystone.Keystone)5 Tenant (com.woorea.openstack.keystone.model.Tenant)5 Quantum (com.woorea.openstack.quantum.Quantum)5 MsoTenant (org.onap.so.openstack.beans.MsoTenant)5 Network (com.woorea.openstack.quantum.model.Network)4 CloudIdentity (org.onap.so.db.catalog.beans.CloudIdentity)4 Metadata (com.woorea.openstack.keystone.model.Metadata)3 ArrayList (java.util.ArrayList)3 NetworkInfoMapper (org.onap.so.openstack.mappers.NetworkInfoMapper)3 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)2 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)2 Segment (com.woorea.openstack.quantum.model.Segment)2 HashMap (java.util.HashMap)2 List (java.util.List)2 HeatBridgeApi (org.onap.so.heatbridge.HeatBridgeApi)2 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)2