Search in sources :

Example 1 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspManagerImpl method addNuageVspDevice.

@Override
public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
    final NuageVspResource resource = new NuageVspResource();
    final String deviceName = Network.Provider.NuageVsp.getName();
    ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    if (_nuageVspDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
    }
    // While the default VSD port is 8443, clustering via HAProxy will go over port 443 (CLOUD-58)
    int port = cmd.getPort() > 0 ? cmd.getPort() : 443;
    try {
        String apiVersion = null;
        String cmsUserPasswordBase64 = NuageVspUtil.encodePassword(cmd.getPassword());
        NuageVspResourceConfiguration resourceConfiguration = new NuageVspResourceConfiguration().guid(UUID.randomUUID().toString()).zoneId(String.valueOf(physicalNetwork.getDataCenterId())).hostName(cmd.getHostName()).cmsUser(cmd.getUserName()).cmsUserPassword(cmsUserPasswordBase64).port(String.valueOf(port)).apiVersion(NuageVspApiVersion.CURRENT.toString()).retryCount(NuageVspConstants.DEFAULT_API_RETRY_COUNT.toString()).retryInterval(NuageVspConstants.DEFAULT_API_RETRY_INTERVAL.toString()).apiRelativePath("/nuage");
        VspHost vspHost = resourceConfiguration.buildVspHost();
        NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(vspHost);
        VspApiDefaults apiDefaults = clientLoader.getNuageVspManagerClient().getApiDefaults();
        if (StringUtils.isNotBlank(cmd.getApiVersion())) {
            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(cmd.getApiVersion())) {
                throw new CloudRuntimeException("Unsupported API version : " + cmd.getApiVersion());
            }
            apiVersion = cmd.getApiVersion();
        } else {
            boolean apiVersionFound = false;
            Map<NuageVspApiVersion, NuageVspApiVersion.Status> supportedVersions = clientLoader.getNuageVspManagerClient().getSupportedVersions();
            for (NuageVspApiVersion selectedVersion : supportedVersions.keySet()) {
                if (supportedVersions.get(selectedVersion) == NuageVspApiVersion.Status.CURRENT) {
                    apiVersion = selectedVersion.toString();
                    apiVersionFound = true;
                    break;
                }
            }
            if (!apiVersionFound) {
                throw new CloudRuntimeException("No supported API version found!");
            }
        }
        String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), apiDefaults.getRetryCount()));
        String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), apiDefaults.getRetryInterval()));
        resourceConfiguration.apiVersion(apiVersion).apiRelativePath("/nuage/api/" + apiVersion).retryCount(retryCount).retryInterval(retryInterval);
        Map<String, String> hostDetails = resourceConfiguration.build();
        resource.configure("Nuage VSD - " + cmd.getHostName(), Maps.<String, Object>newHashMap(hostDetails));
        Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, hostDetails);
        if (host == null) {
            throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
        }
        NuageVspDeviceVO nuageVspDevice = new NuageVspDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
        _nuageVspDao.persist(nuageVspDevice);
        DetailVO detail = new DetailVO(host.getId(), "nuagevspdeviceid", String.valueOf(nuageVspDevice.getId()));
        _hostDetailsDao.persist(detail);
        NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
        String cmsId;
        if (matchingNuageVspDevice != null) {
            cmsId = findNuageVspCmsIdForDeviceOrHost(matchingNuageVspDevice.getId(), matchingNuageVspDevice.getHostId());
        } else {
            SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
            SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
            if (answer != null && answer.getSuccess()) {
                cmsId = answer.getNuageVspCmsId();
            } else {
                throw new CloudRuntimeException("Failed to register CMS ID");
            }
        }
        host = findNuageVspHost(nuageVspDevice.getHostId());
        registerNewNuageVspDevice(host.getId(), cmsId);
        resourceConfiguration.nuageVspCmsId(cmsId);
        resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
        if (matchingNuageVspDevice == null) {
            auditDomainsOnVsp((HostVO) host, true);
        }
        return nuageVspDevice;
    } catch (ConfigurationException e) {
        s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
        throw new CloudRuntimeException("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
    } catch (ExecutionException ee) {
        s_logger.error("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
        throw new CloudRuntimeException("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
    }
}
Also used : NuageVspResourceConfiguration(com.cloud.network.resource.NuageVspResourceConfiguration) VspApiDefaults(net.nuage.vsp.acs.client.api.model.VspApiDefaults) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NuageVspApiVersion(net.nuage.vsp.acs.client.common.NuageVspApiVersion) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) VspHost(net.nuage.vsp.acs.client.api.model.VspHost) ExecutionException(java.util.concurrent.ExecutionException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Status(com.cloud.host.Status) NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) ExternalNetworkDeviceManager(org.apache.cloudstack.network.ExternalNetworkDeviceManager) VspHost(net.nuage.vsp.acs.client.api.model.VspHost) Host(com.cloud.host.Host) NuageVspResource(com.cloud.network.resource.NuageVspResource) DetailVO(com.cloud.host.DetailVO) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) SyncNuageVspCmsIdCommand(com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand) NuageVspPluginClientLoader(net.nuage.vsp.acs.client.api.NuageVspPluginClientLoader)

Example 2 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspManagerImpl method executeSyncCmsId.

public boolean executeSyncCmsId(NuageVspDeviceVO nuageVspDevice, SyncType syncType) {
    NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
    if (syncType == SyncType.REGISTER && matchingNuageVspDevice != null) {
        String cmsId = findNuageVspCmsIdForDeviceOrHost(matchingNuageVspDevice.getId(), matchingNuageVspDevice.getHostId());
        registerNewNuageVspDevice(nuageVspDevice.getHostId(), cmsId);
        return true;
    }
    String cmsId = findNuageVspCmsIdForDeviceOrHost(nuageVspDevice.getId(), nuageVspDevice.getHostId());
    SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(syncType, cmsId);
    SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
    if (answer != null) {
        if (answer.getSuccess()) {
            if (syncType == SyncType.REGISTER || answer.getSyncType() == SyncType.REGISTER) {
                registerNewNuageVspDevice(nuageVspDevice.getHostId(), answer.getNuageVspCmsId());
            } else if (syncType == SyncType.UNREGISTER) {
                removeLegacyNuageVspDeviceCmsId(nuageVspDevice.getId());
            }
        } else if (syncType == SyncType.AUDIT || syncType == SyncType.AUDIT_ONLY) {
            s_logger.fatal("Nuage VSP Device with ID " + nuageVspDevice.getId() + " is configured with an unknown CMS ID!");
        }
    }
    return answer != null && answer.getSuccess();
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) SyncNuageVspCmsIdCommand(com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand)

Example 3 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class ListNuageVspDevicesCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<NuageVspDeviceVO> nuageDevices = _nuageVspManager.listNuageVspDevices(this);
        ListResponse<NuageVspDeviceResponse> response = new ListResponse<NuageVspDeviceResponse>();
        List<NuageVspDeviceResponse> nuageDevicesResponse = new ArrayList<NuageVspDeviceResponse>();
        if (nuageDevices != null && !nuageDevices.isEmpty()) {
            for (NuageVspDeviceVO nuageDeviceVO : nuageDevices) {
                NuageVspDeviceResponse nuageDeviceResponse = _nuageVspManager.createNuageVspDeviceResponse(nuageDeviceVO);
                nuageDevicesResponse.add(nuageDeviceResponse);
            }
        }
        response.setResponses(nuageDevicesResponse);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) NuageVspDeviceResponse(com.cloud.api.response.NuageVspDeviceResponse)

Example 4 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspElementTest method testApplyStaticNats.

@Test
public void testApplyStaticNats() throws CloudException {
    final Network network = mock(Network.class);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getVpcId()).thenReturn(null);
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    final DomainVO domVo = mock(DomainVO.class);
    when(_domainDao.findById(41l)).thenReturn(domVo);
    final NetworkOfferingVO ntwkoffer = mock(NetworkOfferingVO.class);
    when(ntwkoffer.getId()).thenReturn(NETWORK_ID);
    when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] { nuageVspDevice }));
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    when(_nuageVspManager.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
    final Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    assertTrue(_nuageVspElement.applyStaticNats(network, new ArrayList<StaticNat>()));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) DomainVO(com.cloud.domain.DomainVO) Answer(com.cloud.agent.api.Answer) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) HostVO(com.cloud.host.HostVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 5 with NuageVspDeviceVO

use of com.cloud.network.NuageVspDeviceVO in project cloudstack by apache.

the class NuageVspElementTest method testImplement.

@Test
public void testImplement() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, URISyntaxException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getBroadcastUri()).thenReturn(new URI(""));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(_networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination deployDest = mock(DeployDestination.class);
    final DomainVO dom = mock(DomainVO.class);
    when(dom.getName()).thenReturn("domain");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(dom);
    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);
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] { nuageVspDevice }));
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    when(_nuageVspManager.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_ipAddressDao.listStaticNatPublicIps(NETWORK_ID)).thenReturn(new ArrayList<IPAddressVO>());
    when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
    assertTrue(_nuageVspElement.implement(network, offering, deployDest, context));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) URI(java.net.URI) HostVO(com.cloud.host.HostVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) ReservationContext(com.cloud.vm.ReservationContext) DomainVO(com.cloud.domain.DomainVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) IPAddressVO(com.cloud.network.dao.IPAddressVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Aggregations

NuageVspDeviceVO (com.cloud.network.NuageVspDeviceVO)23 HostVO (com.cloud.host.HostVO)11 NuageTest (com.cloud.NuageTest)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 Test (org.junit.Test)9 DomainVO (com.cloud.domain.DomainVO)8 Answer (com.cloud.agent.api.Answer)7 SyncNuageVspCmsIdAnswer (com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 ArrayList (java.util.ArrayList)6 Network (com.cloud.network.Network)5 PhysicalNetwork (com.cloud.network.PhysicalNetwork)5 SyncNuageVspCmsIdCommand (com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand)4 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)4 NuageVspDeviceResponse (com.cloud.api.response.NuageVspDeviceResponse)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 Account (com.cloud.user.Account)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2