public void open(MessageBus messageBus, String[] subjects) { assert (messageBus != null); assert (subjects != null); _messageBus = messageBus; _subjects = subjects; if (subjects != null) { for (String subject : subjects) { messageBus.subscribe(subject, this); } } }
public void Publish(String subject, Object args) { assert (_eventBus != null); _eventBus.publish(_sender, subject, _scope, args); } }
public void close() { if (_subjects != null) { assert (_messageBus != null); for (String subject : _subjects) { _messageBus.unsubscribe(subject, this); } } }
private void configureMessageBusListener() { messageBus.subscribe(EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, new MessageSubscriber() { @Override public void onPublishMessage(final String senderAddress, String subject, Object args) { final String globalSettingUpdated = (String) args; if (Strings.isNullOrEmpty(globalSettingUpdated)) { return; } if (globalSettingUpdated.equals(ApiServiceConfiguration.ManagementServerAddresses.key()) || globalSettingUpdated.equals(IndirectAgentLBAlgorithm.key())) { propagateMSListToAgents(); } } }); }
private void publishOnEventBus(AsyncJob job, String jobEvent) { _messageBus.publish(null, AsyncJob.Topics.JOB_EVENT_PUBLISH, PublishScope.LOCAL, new Pair<AsyncJob, String>(job, jobEvent)); }
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { _messageBus.subscribe(AsyncJob.Topics.JOB_HEARTBEAT, MessageDispatcher.getDispatcher(this)); _timer.scheduleAtFixedRate(new ManagedContextTimerTask() { @Override protected void runInContext() { heartbeat(); } }, _inactivityCheckIntervalMs, _inactivityCheckIntervalMs); return true; }
/** * Publish pre-remove and remove domain events and remove domain * @param domain domain to remove * @throws CloudRuntimeException when domain cannot be removed */ protected void publishRemoveEventsAndRemoveDomain(DomainVO domain) { _messageBus.publish(_name, MESSAGE_PRE_REMOVE_DOMAIN_EVENT, PublishScope.LOCAL, domain); if (!_domainDao.remove(domain.getId())) { CloudRuntimeException e = new CloudRuntimeException("Delete failed on domain " + domain.getName() + " (id: " + domain.getId() + "); Please make sure all users and sub domains have been removed from the domain before deleting"); e.addProxyObject(domain.getUuid(), "domainId"); throw e; } _messageBus.publish(_name, MESSAGE_REMOVE_DOMAIN_EVENT, PublishScope.LOCAL, domain); }
@Override public void subscribe() { /* subscribe to DB events */ _messageBus.subscribe(EventTypes.EVENT_PROJECT_CREATE, MessageDispatcher.getDispatcher(this)); _messageBus.subscribe(EventTypes.EVENT_PROJECT_DELETE, MessageDispatcher.getDispatcher(this)); _messageBus.subscribe(EventTypes.EVENT_DOMAIN_CREATE, MessageDispatcher.getDispatcher(this)); _messageBus.subscribe(EventTypes.EVENT_DOMAIN_DELETE, MessageDispatcher.getDispatcher(this)); } }
@Override public AffinityGroupVO doInTransaction(TransactionStatus status) { AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType, description, affinityGroupDomainId, owner.getId(), aclType); _affinityGroupDao.persist(group); if (aclType == ACLType.Domain) { boolean subDomainAccess = false; subDomainAccess = processor.subDomainAccess(); AffinityGroupDomainMapVO domainMap = new AffinityGroupDomainMapVO(group.getId(), affinityGroupDomainId, subDomainAccess); _affinityGroupDomainMapDao.persist(domainMap); //send event for storing the domain wide resource access Map<String, Object> params = new HashMap<String, Object>(); params.put(ApiConstants.ENTITY_TYPE, AffinityGroup.class); params.put(ApiConstants.ENTITY_ID, group.getId()); params.put(ApiConstants.DOMAIN_ID, affinityGroupDomainId); params.put(ApiConstants.SUBDOMAIN_ACCESS, subDomainAccess); _messageBus.publish(_name, EntityManager.MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT, PublishScope.LOCAL, params); } return group; } });
@Override public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { messageBus.subscribe(AsyncJob.Topics.JOB_EVENT_PUBLISH, MessageDispatcher.getDispatcher(this)); return true; }
s_logger.debug("VM state report is updated. host: " + hostId + ", vm id: " + entry.getKey() + ", power state: " + entry.getValue()); _messageBus.publish(null, VirtualMachineManager.Topics.VM_POWER_STATE, PublishScope.GLOBAL, entry.getKey()); } else { if (s_logger.isDebugEnabled()) s_logger.debug("VM state report is updated. host: " + hostId + ", vm id: " + instance.getId() + ", power state: PowerReportMissing "); _messageBus.publish(null, VirtualMachineManager.Topics.VM_POWER_STATE, PublishScope.GLOBAL, instance.getId()); } else { if (s_logger.isDebugEnabled())
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { _executorPool = Executors.newScheduledThreadPool(10, new NamedThreadFactory("OVS")); _cleanupExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("OVS-Cleanup")); // register for network ACL updated for a VPC. _messageBus.subscribe("Network_ACL_Replaced", new NetworkAclEventsSubscriber()); // register for VM state transition updates VirtualMachine.State.getStateMachine().registerListener(this); return true; }
params.put(ApiConstants.DOMAIN_ID, domainId); params.put(ApiConstants.SUBDOMAIN_ACCESS, subdomainAccessFinal == null ? Boolean.TRUE : subdomainAccessFinal); _messageBus.publish(_name, EntityManager.MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT, PublishScope.LOCAL, params);
CloudianAdminHost.value(), CloudianAdminPort.value(), CloudianAdminUser.value())); messageBus.subscribe(AccountManager.MESSAGE_ADD_ACCOUNT_EVENT, new MessageSubscriber() { @Override public void onPublishMessage(String senderAddress, String subject, Object args) { messageBus.subscribe(AccountManager.MESSAGE_REMOVE_ACCOUNT_EVENT, new MessageSubscriber() { @Override public void onPublishMessage(String senderAddress, String subject, Object args) { messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, new MessageSubscriber() { @Override public void onPublishMessage(String senderAddress, String subject, Object args) { messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() { @Override public void onPublishMessage(String senderAddress, String subject, Object args) {
_messageBus.publish(null, AsyncJob.Topics.JOB_STATE, PublishScope.GLOBAL, jobId);
@Override public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException { ReservationContextImpl.init(_entityMgr); VirtualMachineProfileImpl.init(_entityMgr); VmWorkMigrate.init(_entityMgr); _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vm-Operations-Cleanup")); _nodeId = ManagementServerNode.getManagementServerId(); _agentMgr.registerForHostEvents(this, true, true, true); _messageBus.subscribe(VirtualMachineManager.Topics.VM_POWER_STATE, MessageDispatcher.getDispatcher(this)); return true; }
public boolean applyACLItemsToNetwork(final long networkId, final List<NetworkACLItemVO> rules) throws ResourceUnavailableException { final Network network = _networkDao.findById(networkId); boolean handled = false; boolean foundProvider = false; for (final NetworkACLServiceProvider element : _networkAclElements) { final Network.Provider provider = element.getProvider(); final boolean isAclProvider = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.NetworkACL, provider); if (!isAclProvider) { continue; } foundProvider = true; s_logger.debug("Applying NetworkACL for network: " + network.getId() + " with Network ACL service provider"); handled = element.applyNetworkACLs(network, rules); if (handled) { // publish message on message bus, so that network elements implementing distributed routing // capability can act on the event _messageBus.publish(_name, "Network_ACL_Replaced", PublishScope.LOCAL, network); break; } } if (!foundProvider) { s_logger.debug("Unable to find NetworkACL service provider for network: " + network.getId()); } return handled; }
@Override public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { _agentMgr.registerForHostEvents(this, true, false, true); VirtualMachine.State.getStateMachine().registerListener(this); _messageBus.subscribe("VM_ReservedCapacity_Free", new MessageSubscriber() { @Override public void onPublishMessage(String senderAddress, String subject, Object obj) { VMInstanceVO vm = ((VMInstanceVO)obj); s_logger.debug("MessageBus message: host reserved capacity released for VM: " + vm.getLastHostId() + ", checking if host reservation can be released for host:" + vm.getLastHostId()); Long hostId = vm.getLastHostId(); checkHostReservationRelease(hostId); } }); _vmCapacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600); String hostReservationReleasePeriod = _configDao.getValue(Config.HostReservationReleasePeriod.key()); if (hostReservationReleasePeriod != null) { _hostReservationReleasePeriod = Long.parseLong(hostReservationReleasePeriod); if (_hostReservationReleasePeriod <= 0) _hostReservationReleasePeriod = Long.parseLong(Config.HostReservationReleasePeriod.getDefaultValue()); } _timer = new Timer("HostReservationReleaseChecker"); _nodeId = ManagementServerNode.getManagementServerId(); return super.configure(name, params); }
@Override @DB @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group") public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long projectId, Long domainId, String affinityGroupName) { AffinityGroupVO group = getAffinityGroup(affinityGroupId, account, projectId, domainId, affinityGroupName); // check permissions Account caller = CallContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, AccessType.OperateEntry, true, group); final Long affinityGroupIdFinal = group.getId(); deleteAffinityGroup(affinityGroupIdFinal); // remove its related ACL permission Pair<Class<?>, Long> params = new Pair<Class<?>, Long>(AffinityGroup.class, affinityGroupIdFinal); _messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, params); if (s_logger.isDebugEnabled()) { s_logger.debug("Deleted affinity group id=" + affinityGroupIdFinal); } return true; }
@DB private void initMessageBusListeners() { _messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, (senderAddress, subject, args) -> { Long domainId = (Long) args; Domain domain = _domainDao.findById(domainId); _messageBus.subscribe(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT, (senderAddress, subject, args) -> { DomainVO domain = (DomainVO) args; List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll(); _messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, (senderAddress, subject, args) -> { DomainVO domain = (DomainVO) args; List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();