Search in sources :

Example 1 with Vserver

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

the class AppcOrchestratorPreProcessor method getVserversForAppc.

protected void getVserversForAppc(BuildingBlockExecution execution, GenericVnf vnf) throws Exception {
    AAIResultWrapper aaiRW = aaiVnfResources.queryVnfWrapperById(vnf);
    if (aaiRW != null && aaiRW.getRelationships().isPresent()) {
        Relationships relationships = aaiRW.getRelationships().get();
        if (relationships != null) {
            List<AAIResourceUri> vserverUris = relationships.getRelatedUris(Types.VSERVER);
            ArrayList<String> vserverIds = new ArrayList<String>();
            ArrayList<String> vserverSelfLinks = new ArrayList<String>();
            for (AAIResourceUri j : vserverUris) {
                String vserverId = j.getURIKeys().get(AAIFluentTypeBuilder.Types.VSERVER.getUriParams().vserverId);
                vserverIds.add(vserverId);
                Optional<Vserver> oVserver = aaiVnfResources.getVserver(j);
                if (oVserver.isPresent()) {
                    Vserver vserver = oVserver.get();
                    String vserverSelfLink = vserver.getVserverSelflink();
                    vserverSelfLinks.add(vserverSelfLink);
                }
            }
            logger.debug("vmIdsArray is: {}", vserverSelfLinks);
            logger.debug("vserverIdsArray is: {}", vserverIds);
            execution.setVariable("vmIdList", vserverSelfLinks);
            execution.setVariable("vserverIdList", vserverIds);
        }
    }
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Vserver(org.onap.aai.domain.yang.Vserver) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 2 with Vserver

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

the class CreateAAInventory method doExecute.

@Override
public void doExecute(TestContext context) {
    final Logger logger = LoggerFactory.getLogger(CreateAAInventory.class);
    try {
        String stackName = context.getVariable("stackName");
        if (stackName != null && stackName.equals("replace_module")) {
            String vServerId = "92272b67-d23f-42ca-87fa-7b06a9ec81f3";
            AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
            AAICommonObjectMapperProvider aaiMapper = new AAICommonObjectMapperProvider();
            InputStream vserverFile = new ClassPathResource("openstack/gr_api/CreateAAIInventory.json").getInputStream();
            Vserver vserver = aaiMapper.getMapper().readValue(vserverFile, Vserver.class);
            AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("cloudOwner", "regionOne").tenant("0422ffb57ba042c0800a29dc85ca70f8").vserver(vServerId));
            aaiResourceClient.create(vserverURI, vserver);
        }
    } catch (Exception e) {
        logger.debug("Exception in CreateAAInventory.doExecute", e);
    }
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver) InputStream(java.io.InputStream) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Logger(org.slf4j.Logger) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 3 with Vserver

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

the class HeatBridgeImpl method getPserverToPciIdMap.

private Map<String, List<String>> getPserverToPciIdMap(List<AAIResourceUri> vserverUris) {
    Map<String, List<String>> pserverToPciIdMap = new HashMap<>();
    for (AAIResourceUri vserverUri : vserverUris) {
        AAIResultWrapper vserverWrapper = resourcesClient.get(vserverUri.depth(Depth.TWO));
        Optional<Relationships> vserverRelationships = vserverWrapper.getRelationships();
        if (vserverRelationships.isPresent() && CollectionUtils.isNotEmpty(vserverRelationships.get().getRelatedLinks(Types.PSERVER))) {
            Vserver vserver = vserverWrapper.asBean(Vserver.class).get();
            List<String> pciIds = HeatBridgeUtils.extractPciIdsFromVServer(vserver);
            if (CollectionUtils.isNotEmpty(pciIds)) {
                List<AAIResourceUri> matchingPservers = vserverRelationships.get().getRelatedUris(Types.PSERVER);
                if (matchingPservers != null && matchingPservers.size() == 1) {
                    pserverToPciIdMap.put(matchingPservers.get(0).getURIKeys().get("hostname"), pciIds);
                }
            }
        }
    }
    return pserverToPciIdMap;
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Vserver(org.onap.aai.domain.yang.Vserver) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) L3InterfaceIpv4AddressList(org.onap.aai.domain.yang.L3InterfaceIpv4AddressList) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) IPAddressString(inet.ipaddr.IPAddressString) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 4 with Vserver

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

the class AaiHelper method getPserverToPciIdMap.

/**
 * From the list vserver objects build a map of compute hosts's name and the PCI IDs linked to it.
 *
 * @param vservers List of vserver AAI objects
 * @return a map of compute names to the PCI ids associated with the compute
 */
public Map<String, List<String>> getPserverToPciIdMap(final List<Vserver> vservers) {
    Map<String, List<String>> pserverToPciIdMap = new HashMap<>();
    for (Vserver vserver : vservers) {
        if (vserver.getLInterfaces() != null) {
            List<String> pciIds = vserver.getLInterfaces().getLInterface().stream().filter(lInterface -> lInterface.getSriovVfs() != null && CollectionUtils.isNotEmpty(lInterface.getSriovVfs().getSriovVf())).flatMap(lInterface -> lInterface.getSriovVfs().getSriovVf().stream()).map(SriovVf::getPciId).collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(pciIds)) {
                List<String> matchingPservers = extractRelationshipDataValue(vserver.getRelationshipList(), HeatBridgeConstants.AAI_PSERVER, HeatBridgeConstants.AAI_PSERVER_HOSTNAME);
                Preconditions.checkState(matchingPservers != null && matchingPservers.size() == 1, "Invalid pserver relationships for vserver: " + vserver.getVserverName());
                pserverToPciIdMap.put(matchingPservers.get(0), pciIds);
            }
        }
    }
    return pserverToPciIdMap;
}
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) Vserver(org.onap.aai.domain.yang.Vserver) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) List(java.util.List)

Example 5 with Vserver

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

the class AaiHelper method buildVserver.

/**
 * Transform Openstack Server object to AAI Vserver object
 *
 * @param serverId Openstack server identifier
 * @param server Openstack server object
 * @return AAI Vserver object
 */
public Vserver buildVserver(final String serverId, final Server server) {
    Vserver vserver = new Vserver();
    vserver.setInMaint(false);
    vserver.setIsClosedLoopDisabled(false);
    vserver.setVserverId(serverId);
    vserver.setVserverName(server.getName());
    vserver.setVserverName2(server.getName());
    server.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY)).findFirst().ifPresent(link -> vserver.setVserverSelflink(link.getHref()));
    return vserver;
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver)

Aggregations

Vserver (org.onap.aai.domain.yang.Vserver)14 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)10 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Logger (org.slf4j.Logger)6 HashMap (java.util.HashMap)5 Collectors (java.util.stream.Collectors)5 RelationshipList (org.onap.aai.domain.yang.RelationshipList)5 AAIResourcesClient (org.onap.aaiclient.client.aai.AAIResourcesClient)5 Types (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Preconditions (com.google.common.base.Preconditions)4 Map (java.util.Map)4 Optional (java.util.Optional)4 CollectionUtils (org.apache.commons.collections.CollectionUtils)4 StringUtils (org.apache.commons.lang3.StringUtils)4 Flavor (org.onap.aai.domain.yang.Flavor)4 Image (org.onap.aai.domain.yang.Image)4 L3Network (org.onap.aai.domain.yang.L3Network)4