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;
}
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);
}
}
}
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);
}
}
}
Aggregations