use of com.cloud.agent.api.manager.CleanUpDomainCommand 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;
}
use of com.cloud.agent.api.manager.CleanUpDomainCommand 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);
}
}
});
}
Aggregations