/** * Consume a cluster event. * * @param event the cluster event. */ @Override public void consume(E event) { if (event != null && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
/** * Consume a cluster event. * * @param event the cluster event. */ @Override public void consume(E event) { if (event != null && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
@Override public void produce(E event) { if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) { if (event instanceof Result || event instanceof Command) event.setSourceNode(node); topic.publish(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, don't produce the cluster event", SWITCH_ID); } } }
@Override public void consume(E event) { // check if event has a specified destination. if ((event.getDestination() == null || event.getDestination().contains(node)) && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
@Override public void consume(E event) { // check if event has a specified destination. if ((event.getDestination() == null || event.getDestination().contains(node)) && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
@Override public void produce(E event) { if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) { if (event instanceof Result || event instanceof Command) event.setSourceNode(node); topic.publish(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, don't produce the cluster event", SWITCH_ID); } } }
@Override public void produce(E event) { if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) { if (event instanceof Result || event instanceof Command) event.setSourceNode(node); try { queue.put(event); } catch (InterruptedException e) { LOGGER.error("CELLAR HAZELCAST: queue producer interrupted", e); } } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, don't produce the cluster event", SWITCH_ID); } } }
@Override public void produce(E event) { if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) { if (event instanceof Result || event instanceof Command) event.setSourceNode(node); try { queue.put(event); } catch (InterruptedException e) { LOGGER.error("CELLAR HAZELCAST: queue producer interrupted", e); } } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, don't produce the cluster event", SWITCH_ID); } } }
/** * Retrieve the correlated command from the store and set the result on the command object. * * @param result the cluster result event. */ @Override public void handle(R result) { if (commandStore != null && commandStore.getPending() != null) { String id = result.getId(); Command command = commandStore.getPending().get(id); if (command != null && handlerSwitch.getStatus().equals(SwitchStatus.ON)) { command.addResults(result); } } }
/** * Retrieve the correlated command from the store and set the result on the command object. * * @param result the cluster result event. */ @Override public void handle(R result) { if (commandStore != null && commandStore.getPending() != null) { String id = result.getId(); Command command = commandStore.getPending().get(id); if (command != null && handlerSwitch.getStatus().equals(SwitchStatus.ON)) { command.addResults(result); } } }
@Override public Object doExecute() throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } // check if the producer is ON if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { System.err.println("Cluster event producer is OFF"); return null; } // check if the bundle is allowed if (!isAllowed(group, Constants.BUNDLES_CONFIG_CATEGORY, bundleId, EventType.OUTBOUND)) { System.err.println("OBR bundle " + bundleId + " is blocked outbound for cluster group " + groupName); return null; } // broadcast a cluster event ClusterObrBundleEvent event = new ClusterObrBundleEvent(bundleId, start, deployOptional); event.setSourceGroup(group); event.setSourceNode(clusterManager.getNode()); eventProducer.produce(event); return null; }
if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { throw new IllegalStateException("Cluster event producer is OFF");
@Override public void handle(ClusterSystemStatisticsEvent event) { if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) { logger.debug("CELLAR SYSTEM STATS: {} switch is OFF, cluster event not handled", SWITCH_ID); return;
@Override protected Object doExecute() throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } // check if the producer is ON if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { System.err.println("Cluster event producer is OFF"); return null; } CellarSupport support = new CellarSupport(); support.setConfigurationAdmin(configurationAdmin); support.setGroupManager(groupManager); support.setClusterManager(clusterManager); // check if the kar is allowed if (support.isAllowed(group, Constants.CATEGORY, name, EventType.OUTBOUND)) { // broadcast cluster event ClusterKarEvent clusterEvent = new ClusterKarEvent(name, true); clusterEvent.setSourceGroup(group); clusterEvent.setInstall(false); eventProducer.produce(clusterEvent); } else { System.err.println("KAR " + name + " is blocked outbound for cluster group " + groupName); } return null; }
@Override protected Object doExecute() throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } // check if the producer is ON if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { System.err.println("Cluster event producer is OFF"); return null; } CellarSupport support = new CellarSupport(); support.setConfigurationAdmin(configurationAdmin); support.setGroupManager(groupManager); support.setClusterManager(clusterManager); // check if the kar is allowed if (support.isAllowed(group, Constants.CATEGORY, url, EventType.OUTBOUND)) { // broadcast cluster event ClusterKarEvent clusterEvent = new ClusterKarEvent(url, true); clusterEvent.setSourceGroup(group); clusterEvent.setInstall(true); eventProducer.produce(clusterEvent); } else { System.err.println("KAR " + url + " is blocked outbound for cluster group " + groupName); } return null; }
@Override public void deployBundle(String groupName, String bundleId, boolean start, boolean deployOptional) throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } // check if the producer is ON if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { throw new IllegalStateException("Cluster event producer is OFF"); } // check if the bundle ID is allowed outbound CellarSupport support = new CellarSupport(); support.setClusterManager(this.clusterManager); support.setGroupManager(this.groupManager); support.setConfigurationAdmin(this.configurationAdmin); if (!support.isAllowed(group, Constants.BUNDLES_CONFIG_CATEGORY, bundleId, EventType.OUTBOUND)) { throw new IllegalArgumentException("OBR bundle " + bundleId + " is blocked outbound for cluster group " + groupName); } // broadcast a cluster event ClusterObrBundleEvent event = new ClusterObrBundleEvent(bundleId, start, deployOptional); event.setSourceGroup(group); event.setSourceNode(clusterManager.getNode()); eventProducer.produce(event); }
/** * Handle the {@code ProducerSwitchCommand} command. * * @param command */ public ConsumerSwitchResult execute(ConsumerSwitchCommand command) { // query if (command.getStatus() == null) { return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, consumer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch consumer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn on the switch consumer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ConsumerSwitchResult(command.getId(), Boolean.FALSE, consumer.getSwitch().getStatus().getValue()); } }
/** * Handle the {@code ProducerSwitchCommand} command. * * @param command */ public ConsumerSwitchResult execute(ConsumerSwitchCommand command) { // query if (command.getStatus() == null) { return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, consumer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch consumer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn on the switch consumer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ConsumerSwitchResult(command.getId(), Boolean.FALSE, consumer.getSwitch().getStatus().getValue()); } }
/** * Execute a producer switch command. * * @param command the producer switch command to execute. * @return the result of the command execution. */ @Override public ProducerSwitchResult execute(ProducerSwitchCommand command) { // query if (command.getStatus() == null) { return new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch producer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn off the switch producer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue()); } }
/** * Execute a producer switch command. * * @param command the producer switch command to execute. * @return the result of the command execution. */ @Override public ProducerSwitchResult execute(ProducerSwitchCommand command) { // query if (command.getStatus() == null) { return new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch producer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn off the switch producer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue()); } }