use of org.onap.aai.domain.yang.LInterface in project so by onap.
the class AAIDataRetrieval method getLinterfacesOfVnf.
public List<LInterface> getLinterfacesOfVnf(String vnfId) {
DSLStartNode startNode = new DSLStartNode(Types.GENERIC_VNF, __.key("vnf-id", vnfId));
DSLQueryBuilder<Start, Node> builder = TraversalBuilder.fragment(startNode).to(__.node(Types.VSERVER).to(__.node(Types.L_INTERFACE).output()));
List<LInterface> linterfaces = getAAIDSLQueryClient().querySingleResource(new DSLQuery(builder.build()), LInterface.class);
return linterfaces;
}
use of org.onap.aai.domain.yang.LInterface in project so by onap.
the class HeatBridgeImplTest method testUpdateLInterfaceVlan.
@Test
public void testUpdateLInterfaceVlan() throws HeatBridgeException {
// Arrange
List<Resource> stackResources = (List<Resource>) extractTestStackResources();
Port port = mock(Port.class);
when(port.getId()).thenReturn("test-port-id");
when(port.getName()).thenReturn("test-port-name");
when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
when(port.getDeviceId()).thenReturn("test-device-id");
LInterface lIf = new LInterface();
lIf.setInterfaceId("test-port-id");
lIf.setInterfaceType("SRIOV");
lIf.setInterfaceName("name");
String pfPciId = "0000:08:00.0";
when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id"));
IP ip = mock(IP.class);
Set<IP> ipSet = new HashSet<>();
ipSet.add(ip);
when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
when(ip.getSubnetId()).thenReturn("testSubnetId");
when(port.getFixedIps()).thenAnswer(x -> ipSet);
Subnet subnet = mock(Subnet.class);
when(subnet.getCidr()).thenReturn("169.254.100.0/24");
when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
Network network = mock(Network.class);
when(network.getId()).thenReturn("test-network-id");
when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
when(network.getProviderSegID()).thenReturn("2345");
when(network.getProviderPhyNet()).thenReturn("ovsnet");
doNothing().when(heatbridge).processOVS(any(), any(), any());
when(osClient.getNetworkById(anyString())).thenReturn(network);
SriovPf sriovPf = new SriovPf();
sriovPf.setPfPciId(pfPciId);
PInterface pIf = mock(PInterface.class);
when(pIf.getInterfaceName()).thenReturn("test-port-id");
when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf));
// Act
heatbridge.createVlanAndSriovVF(port, lIf, "hostname");
// Assert
verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
verify(osClient, times(1)).getNetworkById(anyString());
verify(heatbridge, times(0)).processOVS(any(), any(), any());
}
use of org.onap.aai.domain.yang.LInterface in project so by onap.
the class HeatBridgeImpl method buildAddVserverLInterfacesToAaiAction.
@Override
public void buildAddVserverLInterfacesToAaiAction(final List<Resource> stackResources, final List<String> oobMgtNetIds, String cloudOwner) throws HeatBridgeException {
Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
List<String> portIds = extractStackResourceIdsByResourceType(stackResources, HeatBridgeConstants.OS_PORT_RESOURCE_TYPE);
if (portIds == null)
return;
for (String portId : portIds) {
boolean isL2Multicast = false;
Port port = osClient.getPortById(portId);
Network network = osClient.getNetworkById(port.getNetworkId());
if (!StringUtils.isEmpty(port.getDeviceId())) {
LInterface lIf = new LInterface();
lIf.setInterfaceId(port.getId());
lIf.setInterfaceName(port.getName());
lIf.setMacaddr(port.getMacAddress());
lIf.setNetworkName(network.getName());
lIf.setIsPortMirrored(false);
lIf.setIsIpUnnumbered(false);
lIf.setInMaint(false);
if (port.getProfile() != null && port.getProfile().get("trusted") != null) {
String trusted = port.getProfile().get("trusted").toString();
if (Boolean.parseBoolean(trusted)) {
isL2Multicast = true;
}
}
lIf.setL2Multicasting(isL2Multicast);
lIf.setInterfaceType(getInterfaceType(nodeType, port.getvNicType()));
lIf.setRelationshipList(new RelationshipList());
if (oobMgtNetIds != null && oobMgtNetIds.contains(port.getNetworkId())) {
lIf.setInterfaceRole(OOB_MGT_NETWORK_IDENTIFIER);
} else {
lIf.setInterfaceRole(port.getvNicType());
}
// Update l-interface to the vserver
transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName())), Optional.of(lIf));
updateLInterfaceIps(port, lIf);
if (cloudOwner.equals(env.getProperty("mso.cloudOwner.included", ""))) {
Server server = getOpenstackServerById(port.getDeviceId());
createVlanAndSriovVF(port, lIf, server.getHypervisorHostname());
updateSriovPfToSriovVF(port, lIf);
}
}
}
}
use of org.onap.aai.domain.yang.LInterface in project so by onap.
the class HeatBridgeImpl method createVlanAndSriovVF.
protected void createVlanAndSriovVF(final Port port, final LInterface lIf, final String hostName) throws HeatBridgeException {
// add back all vlan logic
Vlan vlan = new Vlan();
Network network = osClient.getNetworkById(port.getNetworkId());
if (network.getNetworkType() != null && network.getNetworkType().equals(NetworkType.VLAN)) {
vlan.setVlanInterface(port.getName() + network.getProviderSegID());
vlan.setVlanIdOuter(Long.parseLong(network.getProviderSegID()));
vlan.setVlanIdInner(0L);
vlan.setInMaint(false);
vlan.setIsIpUnnumbered(false);
vlan.setIsPrivate(false);
transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).vlan(vlan.getVlanInterface())), Optional.of(vlan));
}
if (!lIf.getInterfaceType().equals(SRIOV)) {
if (nodeType == NodeType.GREENFIELD) {
validatePhysicalNetwork(port, network);
processOVS(lIf, hostName, NodeType.GREENFIELD.getInterfaceName());
} else {
processOVS(lIf, hostName, NodeType.BROWNFIELD.getInterfaceName());
}
}
List<String> privateVlans = (ArrayList<String>) port.getProfile().get(PRIVATE_VLANS);
List<String> publicVlans = (ArrayList<String>) port.getProfile().get(PUBLIC_VLANS);
List<String> vlans = null;
if (publicVlans != null && !publicVlans.isEmpty()) {
vlans = publicVlans.stream().filter(publicVlan -> !Strings.isNullOrEmpty(publicVlan)).collect(Collectors.toList());
} else {
vlans = new ArrayList<>();
}
if (privateVlans != null && !privateVlans.isEmpty()) {
List<String> temp = privateVlans.stream().filter(privateVlan -> !Strings.isNullOrEmpty(privateVlan)).collect(Collectors.toList());
vlans.addAll(temp);
}
vlans.stream().forEach(vlanLocal -> logger.debug("Vlan Id: {}", vlanLocal));
processVlanTag(lIf, vlans);
if (port.getvNicType() != null && port.getvNicType().equalsIgnoreCase(HeatBridgeConstants.OS_SRIOV_PORT_TYPE)) {
SriovVf sriovVf = new SriovVf();
sriovVf.setPciId(port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString());
sriovVf.setNeutronNetworkId(port.getNetworkId());
sriovVf.setVfVlanFilter("0");
sriovVf.setVfVlanAntiSpoofCheck(false);
sriovVf.setVfMacAntiSpoofCheck(false);
transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).sriovVf(sriovVf.getPciId())), Optional.of(sriovVf));
}
}
use of org.onap.aai.domain.yang.LInterface in project so by onap.
the class ExceptionBuilder method processAuditException.
public void processAuditException(DelegateExecutionImpl execution, boolean flowShouldContinue) {
logger.debug("Processing Audit Results");
String auditListString = execution.getVariable("auditInventoryResult");
String processKey = getProcessKey(execution.getDelegateExecution());
if (auditListString != null) {
StringBuilder errorMessage = new StringBuilder();
try {
ExtractPojosForBB extractPojosForBB = getExtractPojosForBB();
VfModule module = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
String cloudRegionId = execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId();
GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
AAIObjectAuditList auditList = objectMapper.getMapper().readValue(auditListString, AAIObjectAuditList.class);
errorMessage = errorMessage.append(auditList.getAuditType() + " VF-Module " + module.getVfModuleId() + " failed due to incomplete AAI vserver inventory population after stack " + auditList.getHeatStackName() + " was successfully " + auditList.getAuditType() + "d in cloud region " + cloudRegionId + ". MSO Audit indicates that the following was not " + auditList.getAuditType() + "d in AAI: ");
Stream<AAIObjectAudit> vServerLInterfaceAuditStream = auditList.getAuditList().stream().filter(auditObject -> auditObject.getAaiObjectType().equals(Types.VSERVER.typeName()) || auditObject.getAaiObjectType().equals(Types.L_INTERFACE.typeName()));
List<AAIObjectAudit> filteredAuditStream = vServerLInterfaceAuditStream.filter(a -> !a.isDoesObjectExist()).collect(Collectors.toList());
for (AAIObjectAudit object : filteredAuditStream) {
if (object.getAaiObjectType().equals(Types.L_INTERFACE.typeName())) {
LInterface li = objectMapper.getMapper().convertValue(object.getAaiObject(), LInterface.class);
errorMessage = errorMessage.append(Types.L_INTERFACE.typeName() + " " + li.getInterfaceId() + ", ");
} else {
Vserver vs = objectMapper.getMapper().convertValue(object.getAaiObject(), Vserver.class);
errorMessage = errorMessage.append(Types.VSERVER.typeName() + " " + vs.getVserverId() + ", ");
}
}
if (errorMessage.length() > 0) {
errorMessage.setLength(errorMessage.length() - 2);
errorMessage = errorMessage.append(".");
}
} catch (IOException | BBObjectNotFoundException e) {
errorMessage = errorMessage.append("process objects in AAI. ");
logger.error("Exception occurred in processAuditException", e);
}
if (flowShouldContinue) {
execution.setVariable("StatusMessage", errorMessage.toString());
} else {
WorkflowException exception = new WorkflowException(processKey, 400, errorMessage.toString(), ONAPComponents.SO);
execution.setVariable("WorkflowException", exception);
execution.setVariable("WorkflowExceptionErrorMessage", errorMessage.toString());
logger.info("Outgoing WorkflowException is {}", exception);
logger.info("Throwing AAIInventoryFailure");
throw new BpmnError("AAIInventoryFailure");
}
} else {
String errorMessage = "Unable to process audit results due to auditInventoryResult being null";
WorkflowException exception = new WorkflowException(processKey, 400, errorMessage, ONAPComponents.SO);
execution.setVariable("WorkflowException", exception);
execution.setVariable("WorkflowExceptionErrorMessage", errorMessage);
logger.info("Outgoing WorkflowException is {}", exception);
logger.info("Throwing AAIInventoryFailure");
throw new BpmnError("AAIInventoryFailure");
}
}
Aggregations