Search in sources :

Example 1 with SyncDomainCommand

use of com.cloud.agent.api.sync.SyncDomainCommand in project cloudstack by apache.

the class NuageVspManagerImpl method auditDomainsOnVsp.

private boolean auditDomainsOnVsp(HostVO host, boolean add) {
    List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
    if (CollectionUtils.isEmpty(nuageVspDevices)) {
        return true;
    }
    final SyncDomainCommand.Type action = add ? SyncDomainCommand.Type.ADD : SyncDomainCommand.Type.REMOVE;
    _hostDao.loadDetails(host);
    List<DomainVO> allDomains = _domainDao.listAll();
    for (DomainVO domain : allDomains) {
        if (action == SyncDomainCommand.Type.REMOVE) {
            VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
            CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
            Answer answer = _agentMgr.easySend(host.getId(), cmd);
            if (!answer.getResult()) {
                return false;
            }
        }
        VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
        SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, action);
        Answer answer = _agentMgr.easySend(host.getId(), cmd);
        if (!answer.getResult()) {
            return false;
        }
    }
    return true;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) DomainVO(com.cloud.domain.DomainVO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) CleanUpDomainCommand(com.cloud.agent.api.manager.CleanUpDomainCommand) VspDomainCleanUp(net.nuage.vsp.acs.client.api.model.VspDomainCleanUp) SyncDomainCommand(com.cloud.agent.api.sync.SyncDomainCommand)

Example 2 with SyncDomainCommand

use of com.cloud.agent.api.sync.SyncDomainCommand 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)

Aggregations

CleanUpDomainCommand (com.cloud.agent.api.manager.CleanUpDomainCommand)2 SyncDomainCommand (com.cloud.agent.api.sync.SyncDomainCommand)2 DomainVO (com.cloud.domain.DomainVO)2 NuageVspDeviceVO (com.cloud.network.NuageVspDeviceVO)2 VspDomain (net.nuage.vsp.acs.client.api.model.VspDomain)2 VspDomainCleanUp (net.nuage.vsp.acs.client.api.model.VspDomainCleanUp)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 GetApiDefaultsAnswer (com.cloud.agent.api.manager.GetApiDefaultsAnswer)1 SyncNuageVspCmsIdAnswer (com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer)1 Domain (com.cloud.domain.Domain)1 DB (com.cloud.utils.db.DB)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MessageSubscriber (org.apache.cloudstack.framework.messagebus.MessageSubscriber)1