Search in sources :

Example 1 with HeatBridgeException

use of org.onap.so.heatbridge.HeatBridgeException in project so by onap.

the class MsoCloudClientFactoryImpl method getOpenstackClient.

@Override
public OpenstackClient getOpenstackClient(@Nonnull String url, @Nonnull String msoId, @Nonnull String msoPass, @Nonnull String regionId, @Nonnull String tenantId, @Nonnull String keystoneVersion, String userDomainName, String projectDomainName) throws HeatBridgeException {
    Objects.requireNonNull(url, "Null openstack url!");
    Objects.requireNonNull(msoId, "Null openstack user id!");
    Objects.requireNonNull(msoPass, "Null openstack password!");
    Objects.requireNonNull(regionId, "Null regionId ID!");
    Objects.requireNonNull(tenantId, "Null tenant ID!");
    Objects.requireNonNull(keystoneVersion, "Null keystone version");
    if (userDomainName == null) {
        userDomainName = HeatBridgeConstants.OS_DEFAULT_DOMAIN_NAME;
    }
    if (projectDomainName == null) {
        projectDomainName = HeatBridgeConstants.OS_DEFAULT_DOMAIN_NAME;
    }
    try {
        final OpenstackAccess osAccess = // keystone URL
        new OpenstackAccessBuilder().setBaseUrl(url).setUser(// keystone username
        msoId).setPassword(// keystone decrypted password
        CryptoUtils.decryptCloudConfigPassword(msoPass)).setRegion(// openstack region
        regionId).setDomainName(userDomainName).setProjectName(projectDomainName).setTenantId(// tenantId
        tenantId).build();
        // Identify the Keystone version
        if (keystoneVersion.equals(HeatBridgeConstants.OS_KEYSTONE_V2_KEY)) {
            return openstackClientFactory.createOpenstackV2Client(osAccess);
        } else if (keystoneVersion.equals(HeatBridgeConstants.OS_KEYSTONE_V3_KEY)) {
            return openstackClientFactory.createOpenstackV3Client(osAccess);
        }
        throw new OpenstackClientException("Unsupported keystone version! " + keystoneVersion);
    } catch (OpenstackClientException osClientEx) {
        logger.error("Error creating OS Client", osClientEx);
        throw new HeatBridgeException("Client error when authenticating with the Openstack", osClientEx);
    }
}
Also used : HeatBridgeException(org.onap.so.heatbridge.HeatBridgeException) OpenstackAccess(org.onap.so.heatbridge.openstack.api.OpenstackAccess) OpenstackClientException(org.onap.so.heatbridge.openstack.api.OpenstackClientException) OpenstackAccessBuilder(org.onap.so.heatbridge.openstack.api.OpenstackAccess.OpenstackAccessBuilder)

Example 2 with HeatBridgeException

use of org.onap.so.heatbridge.HeatBridgeException in project so by onap.

the class AaiHelper method createVnfRelationshiptoVserver.

public Relationship createVnfRelationshiptoVserver(String vserverName, String genericVnfId, String vfModuleId) throws HeatBridgeException {
    AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
    AAIResultWrapper vfModule = resourcesClient.get(vfModuleUri);
    if (vfModule.hasRelationshipsTo(Types.VNFC)) {
        List<AAIResourceUri> vnfcUris = vfModule.getRelationships().get().getRelatedUris(Types.VNFC);
        Optional<AAIResourceUri> foundVnfcURI = vnfcUris.stream().filter(resourceUri -> resourceUri.getURIKeys().get("vnfc-name").startsWith(vserverName)).findFirst();
        if (!foundVnfcURI.isPresent()) {
            throw new HeatBridgeException("Cannot Find VNFC to create edge to VServer");
        } else {
            return buildRelationship(foundVnfcURI.get());
        }
    } else {
        throw new HeatBridgeException("VF Module contains no relationships to VNFCS, cannot build edge to VServer");
    }
}
Also used : AAIUriFactory(org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory) Network(org.openstack4j.model.network.Network) Relationship(org.onap.aai.domain.yang.Relationship) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) Server(org.openstack4j.model.compute.Server) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) HeatBridgeConstants(org.onap.so.heatbridge.constants.HeatBridgeConstants) Pserver(org.onap.aai.domain.yang.Pserver) L3Network(org.onap.aai.domain.yang.L3Network) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Port(org.openstack4j.model.network.Port) RelationshipData(org.onap.aai.domain.yang.RelationshipData) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) Logger(org.slf4j.Logger) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) Collection(java.util.Collection) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) HeatBridgeException(org.onap.so.heatbridge.HeatBridgeException) Subnet(org.openstack4j.model.network.Subnet) Collectors(java.util.stream.Collectors) List(java.util.List) Vserver(org.onap.aai.domain.yang.Vserver) Optional(java.util.Optional) Flavor(org.onap.aai.domain.yang.Flavor) PInterface(org.onap.aai.domain.yang.PInterface) Preconditions(com.google.common.base.Preconditions) SriovVf(org.onap.aai.domain.yang.SriovVf) Image(org.onap.aai.domain.yang.Image) HeatBridgeException(org.onap.so.heatbridge.HeatBridgeException) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Aggregations

HeatBridgeException (org.onap.so.heatbridge.HeatBridgeException)2 Preconditions (com.google.common.base.Preconditions)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Flavor (org.onap.aai.domain.yang.Flavor)1 Image (org.onap.aai.domain.yang.Image)1 L3Network (org.onap.aai.domain.yang.L3Network)1 PInterface (org.onap.aai.domain.yang.PInterface)1 Pserver (org.onap.aai.domain.yang.Pserver)1 Relationship (org.onap.aai.domain.yang.Relationship)1 RelationshipData (org.onap.aai.domain.yang.RelationshipData)1 RelationshipList (org.onap.aai.domain.yang.RelationshipList)1 SriovVf (org.onap.aai.domain.yang.SriovVf)1