Search in sources :

Example 16 with NuageVspDeviceVO

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

the class NuageVspManagerImpl method initMessageBusListeners.

@DB
private void initMessageBusListeners() {
    // Create corresponding enterprise and profile in VSP when creating a CS Domain
    _messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, new MessageSubscriber() {

        @Override
        public void onPublishMessage(String senderAddress, String subject, Object args) {
            Long domainId = (Long) args;
            Domain domain = _domainDao.findById(domainId);
            try {
                _domainDao.acquireInLockTable(domain.getId());
                List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
                for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                    VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
                    SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.ADD);
                    _agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
                }
            } finally {
                _domainDao.releaseFromLockTable(domain.getId());
            }
        }
    });
    // Clean up corresponding resources in VSP when deleting a CS Domain
    _messageBus.subscribe(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {

        @Override
        public void onPublishMessage(String senderAddress, String subject, Object args) {
            DomainVO domain = (DomainVO) args;
            List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
            for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
                CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
                _agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
            }
        }
    });
    // Delete corresponding enterprise and profile in VSP when deleting a CS Domain
    _messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {

        @Override
        public void onPublishMessage(String senderAddress, String subject, Object args) {
            DomainVO domain = (DomainVO) args;
            List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
            for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
                SyncDomainCommand syncCmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.REMOVE);
                _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
            }
        }
    });
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) MessageSubscriber(org.apache.cloudstack.framework.messagebus.MessageSubscriber) SyncDomainCommand(com.cloud.agent.api.sync.SyncDomainCommand) DomainVO(com.cloud.domain.DomainVO) CleanUpDomainCommand(com.cloud.agent.api.manager.CleanUpDomainCommand) VspDomainCleanUp(net.nuage.vsp.acs.client.api.model.VspDomainCleanUp) ArrayList(java.util.ArrayList) List(java.util.List) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) Domain(com.cloud.domain.Domain) DB(com.cloud.utils.db.DB)

Example 17 with NuageVspDeviceVO

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

the class AddNuageVspDeviceCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        NuageVspDeviceVO nuageVspDeviceVO = _nuageVspManager.addNuageVspDevice(this);
        if (nuageVspDeviceVO != null) {
            NuageVspDeviceResponse response = _nuageVspManager.createNuageVspDeviceResponse(nuageVspDeviceVO);
            response.setObjectName("nuagevspdevice");
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nuage VSP device due to internal error.");
        }
    } 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) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NuageVspDeviceResponse(com.cloud.api.response.NuageVspDeviceResponse)

Example 18 with NuageVspDeviceVO

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

the class UpdateNuageVspDeviceCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        NuageVspDeviceVO nuageVspDeviceVO = _nuageVspManager.updateNuageVspDevice(this);
        if (nuageVspDeviceVO != null) {
            NuageVspDeviceResponse response = _nuageVspManager.createNuageVspDeviceResponse(nuageVspDeviceVO);
            response.setObjectName("nuagevspdevice");
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nuage VSP device due to internal error.");
        }
    } 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) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NuageVspDeviceResponse(com.cloud.api.response.NuageVspDeviceResponse)

Example 19 with NuageVspDeviceVO

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

the class NuageVspElementTest method testApplyNetworkACL.

@Test
public void testApplyNetworkACL() throws Exception {
    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 NetworkOfferingVO ntwkoffer = mock(NetworkOfferingVO.class);
    when(ntwkoffer.getId()).thenReturn(NETWORK_ID);
    when(ntwkoffer.getEgressDefaultPolicy()).thenReturn(true);
    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.applyNetworkACLs(network, new ArrayList<NetworkACLItem>()));
}
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 20 with NuageVspDeviceVO

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

the class NuageVspElementTest method testShutdownVpc.

@Test
public void testShutdownVpc() throws Exception {
    final Vpc vpc = mock(Vpc.class);
    when(vpc.getUuid()).thenReturn("aaaaaa");
    when(vpc.getState()).thenReturn(Vpc.State.Inactive);
    when(vpc.getDomainId()).thenReturn(NETWORK_ID);
    when(vpc.getZoneId()).thenReturn(NETWORK_ID);
    when(vpc.getId()).thenReturn(NETWORK_ID);
    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);
    PhysicalNetworkVO physNet = mock(PhysicalNetworkVO.class);
    when(physNet.getIsolationMethods()).thenReturn(Lists.newArrayList(PhysicalNetwork.IsolationMethod.VSP.name()));
    when(physNet.getId()).thenReturn(NETWORK_ID);
    when(_physicalNetworkDao.listByZone(NETWORK_ID)).thenReturn(Lists.newArrayList(physNet));
    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(Lists.newArrayList(nuageVspDevice));
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    when(_nuageVspManager.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    DomainRouterVO domainRouter = mock(DomainRouterVO.class);
    when(domainRouter.getUuid()).thenReturn("aaaaaa");
    when(_domainRouterDao.listByVpcId(NETWORK_ID)).thenReturn(Lists.newArrayList(domainRouter));
    final Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    assertTrue(_nuageVspElement.shutdownVpc(vpc, context));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) DomainVO(com.cloud.domain.DomainVO) Account(com.cloud.user.Account) Answer(com.cloud.agent.api.Answer) Vpc(com.cloud.network.vpc.Vpc) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HostVO(com.cloud.host.HostVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) ReservationContext(com.cloud.vm.ReservationContext) 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