Search in sources :

Example 1 with Image

use of org.onap.aai.domain.yang.Image in project so by onap.

the class AaiHelper method buildImage.

/**
 * Transform Openstack Image object to AAI Image object
 *
 * @param image Openstack Image object
 * @return AAI Image object
 */
public Image buildImage(final org.openstack4j.model.compute.Image image) {
    Image aaiImage = new Image();
    aaiImage.setImageId(image.getId());
    aaiImage.setImageName(image.getName());
    aaiImage.setImageOsDistro(HeatBridgeConstants.OS_UNKNOWN_KEY);
    aaiImage.setImageOsVersion(HeatBridgeConstants.OS_UNKNOWN_KEY);
    // application name/vendor/version needs to be set
    if (image.getLinks() != null) {
        image.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY)).findFirst().ifPresent(link -> aaiImage.setImageSelflink(link.getHref()));
    }
    if (aaiImage.getImageSelflink() == null || aaiImage.getImageSelflink().isEmpty()) {
        aaiImage.setImageSelflink("NA");
    }
    return aaiImage;
}
Also used : Image(org.onap.aai.domain.yang.Image)

Example 2 with Image

use of org.onap.aai.domain.yang.Image in project so by onap.

the class HeatBridgeImpl method buildAddImagesToAaiAction.

@Override
public void buildAddImagesToAaiAction(final List<org.openstack4j.model.compute.Image> images) throws HeatBridgeException {
    for (org.openstack4j.model.compute.Image image : images) {
        Image aaiImage = aaiHelper.buildImage(image);
        try {
            AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).image(aaiImage.getImageId()));
            if (!resourcesClient.exists(uri)) {
                transaction.create(uri, aaiImage);
                logger.debug("Queuing AAI command to add image: " + aaiImage.getImageId());
            } else {
                logger.debug("Nothing to add since image: " + aaiImage.getImageId() + "already exists in AAI.");
            }
        } catch (WebApplicationException e) {
            throw new HeatBridgeException("Failed to update image to AAI: " + aaiImage.getImageId() + ". Error" + " cause: " + e, e);
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Image(org.onap.aai.domain.yang.Image)

Example 3 with Image

use of org.onap.aai.domain.yang.Image in project so by onap.

the class HeatBridgeImpl method buildAddVserversToAaiAction.

@Override
public void buildAddVserversToAaiAction(final String genericVnfId, final String vfModuleId, final List<Server> servers) throws HeatBridgeException {
    for (Server server : servers) {
        Vserver vserver = aaiHelper.buildVserver(server.getId(), server);
        // Build vserver relationships to: image, flavor, pserver, vf-module
        vserver.setRelationshipList(aaiHelper.getVserverRelationshipList(cloudOwner, cloudRegionId, genericVnfId, vfModuleId, server));
        AAIResourceUri vserverUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(vserver.getVserverId()));
        if (resourcesClient.exists(vserverUri)) {
            AAIResultWrapper existingVserver = resourcesClient.get(vserverUri);
            AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
            if (!existingVserver.hasRelationshipsTo(Types.VNFC)) {
                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(vserver.getVserverName())).findFirst();
                    if (foundVnfcURI.isEmpty()) {
                        throw new HeatBridgeException("Cannot Find VNFC to create edge to VServer");
                    }
                    transaction.connect(vserverUri, foundVnfcURI.get());
                } else {
                /*
                         * throw new HeatBridgeException(
                         * "VF Module contains no relationships to VNFCS, cannot build edge to VServer");
                         */
                }
            }
            if (!existingVserver.hasRelationshipsTo(Types.VF_MODULE)) {
                transaction.connect(vserverUri, vfModuleUri);
            }
            if (!existingVserver.hasRelationshipsTo(Types.PSERVER)) {
                AAIResourceUri pServerUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(server.getHypervisorHostname()));
                transaction.connect(vserverUri, pServerUri);
            }
        } else {
            transaction.create(vserverUri, vserver);
        }
    }
}
Also used : Depth(org.onap.aaiclient.client.graphinventory.entities.uri.Depth) AaiHelper(org.onap.so.heatbridge.helpers.AaiHelper) AAIUriFactory(org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory) Node(org.onap.aaiclient.client.graphinventory.entities.Node) Server(org.openstack4j.model.compute.Server) LoggerFactory(org.slf4j.LoggerFactory) HeatBridgeUtils(org.onap.so.heatbridge.utils.HeatBridgeUtils) StringUtils(org.apache.commons.lang3.StringUtils) DSLQueryBuilder(org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder) Map(java.util.Map) Resource(org.openstack4j.model.heat.Resource) AAIDSLQueryClient(org.onap.aaiclient.client.aai.AAIDSLQueryClient) Vlan(org.onap.aai.domain.yang.Vlan) UriBuilder(javax.ws.rs.core.UriBuilder) Pserver(org.onap.aai.domain.yang.Pserver) TypeReference(com.fasterxml.jackson.core.type.TypeReference) L3Network(org.onap.aai.domain.yang.L3Network) DSLQuery(org.onap.aaiclient.client.graphinventory.entities.DSLQuery) AAISingleTransactionClient(org.onap.aaiclient.client.aai.AAISingleTransactionClient) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) L3InterfaceIpv4AddressList(org.onap.aai.domain.yang.L3InterfaceIpv4AddressList) Collectors(java.util.stream.Collectors) MsoCloudClientFactoryImpl(org.onap.so.heatbridge.factory.MsoCloudClientFactoryImpl) NotFoundException(javax.ws.rs.NotFoundException) IPAddressString(inet.ipaddr.IPAddressString) Objects(java.util.Objects) NetworkType(org.openstack4j.model.network.NetworkType) VolumeAttachment(org.openstack4j.model.storage.block.VolumeAttachment) List(java.util.List) Environment(org.springframework.core.env.Environment) InetAddressValidator(org.apache.commons.validator.routines.InetAddressValidator) SriovPf(org.onap.aai.domain.yang.SriovPf) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) Flavor(org.onap.aai.domain.yang.Flavor) Results(org.onap.aaiclient.client.aai.entities.Results) Volume(org.onap.aai.domain.yang.Volume) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Image(org.onap.aai.domain.yang.Image) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) Network(org.openstack4j.model.network.Network) Relationship(org.onap.aai.domain.yang.Relationship) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) BulkProcessFailed(org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) RelationshipList(org.onap.aai.domain.yang.RelationshipList) CollectionUtils(org.apache.commons.collections.CollectionUtils) ServerType(org.onap.so.db.catalog.beans.ServerType) DSLStartNode(org.onap.aaiclient.client.graphinventory.entities.DSLStartNode) OpenstackClientFactoryImpl(org.onap.so.heatbridge.openstack.factory.OpenstackClientFactoryImpl) IP(org.openstack4j.model.network.IP) Start(org.onap.aaiclient.client.graphinventory.entities.Start) HeatBridgeConstants(org.onap.so.heatbridge.constants.HeatBridgeConstants) SpringContextHelper(org.onap.so.spring.SpringContextHelper) LInterface(org.onap.aai.domain.yang.LInterface) Nonnull(javax.annotation.Nonnull) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) org.onap.aaiclient.client.graphinventory.entities.__(org.onap.aaiclient.client.graphinventory.entities.__) Port(org.openstack4j.model.network.Port) Subnets(org.onap.aai.domain.yang.Subnets) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) Format(org.onap.aaiclient.client.graphinventory.Format) Logger(org.slf4j.Logger) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Subnet(org.openstack4j.model.network.Subnet) Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) TraversalBuilder(org.onap.aaiclient.client.graphinventory.entities.TraversalBuilder) Vserver(org.onap.aai.domain.yang.Vserver) PInterface(org.onap.aai.domain.yang.PInterface) Preconditions(com.google.common.base.Preconditions) SriovVf(org.onap.aai.domain.yang.SriovVf) NodeType(org.onap.so.cloud.resource.beans.NodeType) OpenstackClient(org.onap.so.heatbridge.openstack.api.OpenstackClient) Vserver(org.onap.aai.domain.yang.Vserver) Server(org.openstack4j.model.compute.Server) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Aggregations

Image (org.onap.aai.domain.yang.Image)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IPAddressString (inet.ipaddr.IPAddressString)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1