Hi Devs,
On Fri, Jan 10, 2014 at 3:51 PM, <[email protected]> wrote: > Updated Branches: > refs/heads/master f937bb298 -> 236a1b375 > > > updating cartridge agent and rules file with the modified method > > > Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo > Commit: > http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/236a1b37 > Tree: > http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/236a1b37 > Diff: > http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/236a1b37 > > Branch: refs/heads/master > Commit: 236a1b3755404559d1bd864a84fd5e93b9d35212 > Parents: f937bb2 > Author: rekathiru <[email protected]> > Authored: Fri Jan 10 15:50:41 2014 +0530 > Committer: rekathiru <[email protected]> > Committed: Fri Jan 10 15:50:41 2014 +0530 > > ---------------------------------------------------------------------- > .../stratos/cartridge/agent/CartridgeAgent.java | 49 +++++++++++++------- > .../agent/util/CartridgeAgentConstants.java | 1 + > .../cartridge/agent/util/ExtensionUtils.java | 13 ++++++ > .../InstanceCleanupClusterEventListener.java | 24 ++++++++++ > .../notifier/InstanceCleanupEventListener.java | 25 ---------- > .../InstanceCleanupMemberEventListener.java | 25 ++++++++++ > .../InstanceNotifierMessageProcessorChain.java | 4 +- > .../distribution/src/main/conf/mincheck.drl | 2 +- > 8 files changed, 99 insertions(+), 44 deletions(-) > ---------------------------------------------------------------------- > > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java > ---------------------------------------------------------------------- > diff --git > a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java > b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java > index 3344282..c4fe290 100644 > --- > a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java > +++ > b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java > @@ -12,9 +12,11 @@ import > org.apache.stratos.cartridge.agent.util.CartridgeAgentUtils; > import org.apache.stratos.cartridge.agent.util.ExtensionUtils; > import org.apache.stratos.messaging.event.Event; > import > org.apache.stratos.messaging.event.instance.notifier.ArtifactUpdatedEvent; > +import > org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupClusterEvent; > import > org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupMemberEvent; > import > org.apache.stratos.messaging.listener.instance.notifier.ArtifactUpdateEventListener; > -import > org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupEventListener; > +import > org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupClusterEventListener; > +import > org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupMemberEventListener; > import > org.apache.stratos.messaging.message.processor.instance.notifier.InstanceNotifierMessageProcessorChain; > import > org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventMessageDelegator; > import > org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventMessageReceiver; > @@ -69,10 +71,25 @@ public class CartridgeAgent implements Runnable { > } > }); > > - processorChain.addEventListener(new > InstanceCleanupEventListener() { > + processorChain.addEventListener(new > InstanceCleanupMemberEventListener() { > @Override > protected void onEvent(Event event) { > - onInstanceCleanupEvent((InstanceCleanupMemberEvent) event); > + String memberIdInPayload = > CartridgeAgentConfiguration.getInstance().getClusterId(); > + InstanceCleanupMemberEvent instanceCleanupMemberEvent = > (InstanceCleanupMemberEvent)event; > + > if(memberIdInPayload.equals(instanceCleanupMemberEvent.getMemberId())) { > + onInstanceCleanupEvent(); > + } > + } > + }); > + > + processorChain.addEventListener(new > InstanceCleanupClusterEventListener() { > + @Override > + protected void onEvent(Event event) { > + String clusterIdInPayload = > CartridgeAgentConfiguration.getInstance().getClusterId(); > + InstanceCleanupClusterEvent instanceCleanupClusterEvent = > (InstanceCleanupClusterEvent)event; > + > if(clusterIdInPayload.equals(instanceCleanupClusterEvent.getClusterId())) { > + onInstanceCleanupEvent(); > + } > } > }); > InstanceNotifierEventMessageDelegator messageDelegator = new > InstanceNotifierEventMessageDelegator(processorChain); > @@ -154,20 +171,20 @@ public class CartridgeAgent implements Runnable { > } > } > In CartridgeAgent I'm getting following exception, *Exception in thread "Thread-0" java.lang.RuntimeException: Unknown event listener* * at org.apache.stratos.messaging.message.processor.instance.notifier.InstanceNotifierMessageProcessorChain.addEventListener(InstanceNotifierMessageProcessorChain.java:56)* * at org.apache.stratos.cartridge.agent.CartridgeAgent.run(CartridgeAgent.java:85)* * at java.lang.Thread.run(Thread.java:722)* Reason seems to be that in InstanceNotifierMessageProcessorChain, eventListener was not expected to be a "InstanceCleanupClusterEventListener". Is adding an instance of check for InstanceCleanupClusterEventListener the correct way to fix it? > > - private void onInstanceCleanupEvent(InstanceCleanupMemberEvent event) > { > - InstanceCleanupMemberEvent instanceCleanupEvent = > (InstanceCleanupMemberEvent)event; > - String memberIdInPayload = > CartridgeAgentConfiguration.getInstance().getMemberId(); > - String memberId = instanceCleanupEvent.getMemberId(); > - if(memberId != null && memberId.equals(memberIdInPayload)) { > - if(log.isInfoEnabled()) { > - log.info("Executing cleaning up the data in the > cartridge instance..."); > - } > - // TODO > - //cleaning up the cartridge instance's data > - > - //publishing the Ready to shutdown event after performing the > cleanup > - > CartridgeAgentEventPublisher.publishInstanceReadyToShutdownEvent(); > + private void onInstanceCleanupEvent() { > + if(log.isInfoEnabled()) { > + log.info("Executing cleaning up the data in the cartridge > instance..."); > + } > + //cleaning up the cartridge instance's data > + ExtensionUtils.executeCleanupExtension(); > + if(log.isInfoEnabled()) { > + log.info("cleaning up finished in the cartridge > instance..."); > + } > + if(log.isInfoEnabled()) { > + log.info("publishing ready to shutdown event..."); > } > + //publishing the Ready to shutdown event after performing the > cleanup > + > CartridgeAgentEventPublisher.publishInstanceReadyToShutdownEvent(); > } > > public void terminate() { > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java > ---------------------------------------------------------------------- > diff --git > a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java > b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java > index dc24f28..65a7594 100644 > --- > a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java > +++ > b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/CartridgeAgentConstants.java > @@ -31,6 +31,7 @@ public class CartridgeAgentConstants implements > Serializable{ > public static final String START_SERVERS_SH = "start-servers.sh"; > public static final String INSTANCE_ACTIVATED_SH = > "instance-activated.sh"; > public static final String ARTIFACTS_UPDATED_SH = > "artifacts-updated.sh"; > + public static final String CLEAN_UP_SH = "clean.sh"; > > public static final String CARTRIDGE_KEY = "CARTRIDGE_KEY"; > public static final String APP_PATH = "APP_PATH"; > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java > ---------------------------------------------------------------------- > diff --git > a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java > b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java > index 06b113f..e164022 100644 > --- > a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java > +++ > b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java > @@ -60,6 +60,19 @@ public class ExtensionUtils { > } > } > > + public static void executeCleanupExtension() { > + try { > + if(log.isDebugEnabled()) { > + log.debug("Executing start servers extension"); > + } > + String command = > prepareCommand(CartridgeAgentConstants.CLEAN_UP_SH); > + CommandUtils.executeCommand(command); > + } > + catch (Exception e) { > + log.error("Could not execute start servers extension", e); > + } > + } > + > public static void executeInstanceStartedExtension() { > try { > if(log.isDebugEnabled()) { > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupClusterEventListener.java > ---------------------------------------------------------------------- > diff --git > a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupClusterEventListener.java > b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupClusterEventListener.java > new file mode 100644 > index 0000000..9423b17 > --- /dev/null > +++ > b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupClusterEventListener.java > @@ -0,0 +1,24 @@ > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > +package org.apache.stratos.messaging.listener.instance.notifier; > + > +import org.apache.stratos.messaging.listener.EventListener; > + > +public abstract class InstanceCleanupClusterEventListener extends > EventListener { > +} > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupEventListener.java > ---------------------------------------------------------------------- > diff --git > a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupEventListener.java > b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupEventListener.java > deleted file mode 100644 > index ccc8dbc..0000000 > --- > a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupEventListener.java > +++ /dev/null > @@ -1,25 +0,0 @@ > -/* > - * Licensed to the Apache Software Foundation (ASF) under one > - * or more contributor license agreements. See the NOTICE file > - * distributed with this work for additional information > - * regarding copyright ownership. The ASF licenses this file > - * to you under the Apache License, Version 2.0 (the > - * "License"); you may not use this file except in compliance > - * with the License. You may obtain a copy of the License at > - * > - * http://www.apache.org/licenses/LICENSE-2.0 > - * > - * Unless required by applicable law or agreed to in writing, > - * software distributed under the License is distributed on an > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > - * KIND, either express or implied. See the License for the > - * specific language governing permissions and limitations > - * under the License. > - */ > -package org.apache.stratos.messaging.listener.instance.notifier; > - > -import org.apache.stratos.messaging.listener.EventListener; > - > -public abstract class InstanceCleanupEventListener extends EventListener { > - > -} > \ No newline at end of file > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupMemberEventListener.java > ---------------------------------------------------------------------- > diff --git > a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupMemberEventListener.java > b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupMemberEventListener.java > new file mode 100644 > index 0000000..ae64bbb > --- /dev/null > +++ > b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/listener/instance/notifier/InstanceCleanupMemberEventListener.java > @@ -0,0 +1,25 @@ > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > +package org.apache.stratos.messaging.listener.instance.notifier; > + > +import org.apache.stratos.messaging.listener.EventListener; > + > +public abstract class InstanceCleanupMemberEventListener extends > EventListener { > + > +} > \ No newline at end of file > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java > ---------------------------------------------------------------------- > diff --git > a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java > b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java > index 235c749..b844d2d 100644 > --- > a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java > +++ > b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java > @@ -23,7 +23,7 @@ import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > import org.apache.stratos.messaging.listener.EventListener; > import > org.apache.stratos.messaging.listener.instance.notifier.ArtifactUpdateEventListener; > -import > org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupEventListener; > +import > org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupMemberEventListener; > import > org.apache.stratos.messaging.message.processor.MessageProcessorChain; > > /** > @@ -50,7 +50,7 @@ public class InstanceNotifierMessageProcessorChain > extends MessageProcessorChain > public void addEventListener(EventListener eventListener) { > if (eventListener instanceof ArtifactUpdateEventListener) { > > artifactUpdateMessageProcessor.addEventListener(eventListener); > - } else if (eventListener instanceof InstanceCleanupEventListener) > { > + } else if (eventListener instanceof > InstanceCleanupMemberEventListener) { > > artifactUpdateMessageProcessor.addEventListener(eventListener); > } else { > throw new RuntimeException("Unknown event listener"); > > > http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/236a1b37/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl > ---------------------------------------------------------------------- > diff --git > a/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl > b/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl > index b7bf7e0..2c04459 100755 > --- a/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl > +++ b/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl > @@ -74,6 +74,6 @@ dialect "mvel" > eval(log.debug("[obsolete-check] [network-partition] " + > $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + > " Member id: " + memberId)) > eval($ctxt.removeObsoleteMember(memberId)) > then > - $delegator.delegateTerminate(memberId); > + $delegator.terminateObsoleteInstance(memberId); > end > > > -- *Sajith Kariyawasam* *Senior Software Engineer; WSO2, Inc.* *AMIE (SL)* *Blog: http://sajithblogs.blogspot.com/ <http://sajithblogs.blogspot.com/>* *Mobile: +94772269575*
