use of org.onap.aai.domain.yang.Flavor in project so by onap.
the class HeatBridgeImpl method buildAddFlavorsToAaiAction.
@Override
public void buildAddFlavorsToAaiAction(final List<org.openstack4j.model.compute.Flavor> flavors) throws HeatBridgeException {
for (org.openstack4j.model.compute.Flavor flavor : flavors) {
Flavor aaiFlavor = aaiHelper.buildFlavor(flavor);
try {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).flavor(aaiFlavor.getFlavorId()));
transaction.createIfNotExists(uri, Optional.of(aaiFlavor));
} catch (WebApplicationException e) {
throw new HeatBridgeException("Failed to update flavor to AAI: " + aaiFlavor.getFlavorId() + ". Error" + " cause: " + e, e);
}
}
}
use of org.onap.aai.domain.yang.Flavor in project so by onap.
the class AaiHelper method buildFlavor.
/**
* Transform Openstack Flavor object to AAI Flavor object
*
* @param flavor Openstack Flavor object
* @return AAI Flavor object
*/
public Flavor buildFlavor(final org.openstack4j.model.compute.Flavor flavor) {
Flavor aaiFlavor = new Flavor();
aaiFlavor.setFlavorId(flavor.getId());
aaiFlavor.setFlavorName(flavor.getName());
aaiFlavor.setFlavorVcpus(flavor.getVcpus());
aaiFlavor.setFlavorRam(flavor.getRam());
aaiFlavor.setFlavorDisk(flavor.getDisk());
aaiFlavor.setFlavorEphemeral(flavor.getEphemeral());
aaiFlavor.setFlavorDisabled(flavor.isDisabled());
aaiFlavor.setFlavorIsPublic(flavor.isPublic());
aaiFlavor.setFlavorSwap(Integer.toString(flavor.getSwap()));
flavor.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY)).findFirst().ifPresent(link -> aaiFlavor.setFlavorSelflink(link.getHref()));
return aaiFlavor;
}
use of org.onap.aai.domain.yang.Flavor 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