use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.
the class NiciraNvpElementTest method implementSharedNetworkNumericalVlanIdTest.
@Test
public void implementSharedNetworkNumericalVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
// SHARED NETWORKS CASE 2: NUMERICAL VLAN ID
final Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getGuestType()).thenReturn(GuestType.Shared);
when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
HostVO niciraNvpHost = mock(HostVO.class);
when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Shared);
final DeployDestination dest = mock(DeployDestination.class);
final Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext context = mock(ReservationContext.class);
when(context.getDomain()).thenReturn(dom);
when(context.getAccount()).thenReturn(acc);
//SHARED NETWORKS CASE 2
when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(false);
VlanVO vlanVO = mock(VlanVO.class);
when(vlanVO.getVlanTag()).thenReturn("111");
when(vlanDao.listVlansByNetworkId(NETWORK_ID)).thenReturn(Arrays.asList(new VlanVO[] { vlanVO }));
when(niciraNvpHost.getDetail("l2gatewayserviceuuid")).thenReturn("bbbb-bbbb-bbbb");
final ConfigureSharedNetworkVlanIdAnswer answer = mock(ConfigureSharedNetworkVlanIdAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command) any())).thenReturn(answer);
assertTrue(element.implement(network, offering, dest, context));
}
use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.
the class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper method execute.
@Override
public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
final String logicalSwitchUuid = command.getLogicalSwitchUuid();
final String l2GatewayServiceUuid = command.getL2GatewayServiceUuid();
long vlanId = command.getVlanId();
final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
final long networkId = command.getNetworkId();
s_logger.debug("Connecting Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + " network " + networkId);
final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid);
LogicalSwitchPort lSwitchPort = null;
try {
lSwitchPort = new LogicalSwitchPort();
lSwitchPort.setAdminStatusEnabled(true);
lSwitchPort.setDisplayName(niciraNvpResource.truncate(networkId + "-l2Gateway-port", NAME_MAX_LEN));
lSwitchPort.setTags(tags);
lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
} catch (NiciraNvpApiException e) {
s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " due to: " + e.getMessage() + ", retrying");
return handleException(e, command, niciraNvpResource);
}
s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid);
s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
try {
final L2GatewayAttachment attachment = new L2GatewayAttachment(l2GatewayServiceUuid);
if (command.getVlanId() != 0) {
attachment.setVlanId(command.getVlanId());
}
niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), attachment);
} catch (NiciraNvpApiException e) {
s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", errorCode: " + e.getErrorCode());
cleanup(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
return handleException(e, command, niciraNvpResource);
}
s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
s_logger.debug("Successfully connected Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + ", network " + networkId + ", through Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ")");
return new ConfigureSharedNetworkVlanIdAnswer(command, true, "OK");
}
use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.
the class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper method handleException.
private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
if (HttpStatusCodeHelper.isConflict(e.getErrorCode())) {
s_logger.warn("There's been a conflict in NSX side, aborting implementation");
return new ConfigureSharedNetworkVlanIdAnswer(command, false, "FAILED: There's been a conflict in NSX side");
} else {
s_logger.warn("Error code: " + e.getErrorCode() + ", retrying");
final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
retryUtility.addRetry(command, NUM_RETRIES);
return retryUtility.retry(command, ConfigureSharedNetworkVlanIdAnswer.class, e);
}
}
use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.
the class NiciraNvpElement method sharedNetworkSupportNumericalVlanId.
private boolean sharedNetworkSupportNumericalVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) {
List<VlanVO> networkVlans = vlanDao.listVlansByNetworkId(network.getId());
if (networkVlans.size() == 1) {
for (VlanVO vlanVO : networkVlans) {
long vlanId = Long.parseLong(vlanVO.getVlanTag());
String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid");
if (l2GatewayServiceUuid == null) {
throw new CloudRuntimeException("No L2 Gateway Service Uuid found on " + niciraNvpHost.getName());
}
ConfigureSharedNetworkVlanIdCommand cmd = new ConfigureSharedNetworkVlanIdCommand(lSwitchUuid, l2GatewayServiceUuid, vlanId, ownerName, network.getId());
ConfigureSharedNetworkVlanIdAnswer answer = (ConfigureSharedNetworkVlanIdAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) {
s_logger.error("Failed to configure Shared network " + network.getDisplayText());
return false;
}
}
}
return true;
}
Aggregations