You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/03/21 12:21:10 UTC
[2/3] stratos git commit: Implementing stratos component startup
synchronizer
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java
new file mode 100644
index 0000000..ffef662
--- /dev/null
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java
@@ -0,0 +1,179 @@
+/*
+ * 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.common.internal;
+
+import com.hazelcast.core.HazelcastInstance;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.clustering.impl.HazelcastDistributedObjectProvider;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.common.services.ComponentStartUpSynchronizer;
+import org.apache.stratos.common.services.DistributedObjectProvider;
+import org.apache.stratos.common.util.CommonUtil;
+import org.apache.stratos.common.util.StratosConfiguration;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.caching.impl.DistributedMapProvider;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.utils.ConfigurationContextService;
+
+/**
+ * @scr.component name="apache.stratos.common" immediate="true"
+ * @scr.reference name="hazelcast.instance.service" interface="com.hazelcast.core.HazelcastInstance"
+ * cardinality="0..1"policy="dynamic" bind="setHazelcastInstance" unbind="unsetHazelcastInstance"
+ * @scr.reference name="distributedMapProvider" interface="org.wso2.carbon.caching.impl.DistributedMapProvider"
+ * cardinality="0..1" policy="dynamic" bind="setDistributedMapProvider" unbind="unsetDistributedMapProvider"
+ * @scr.reference name="registry.service"
+ * interface="org.wso2.carbon.registry.core.service.RegistryService"
+ * cardinality="1..1" policy="dynamic" bind="setRegistryService"
+ * unbind="unsetRegistryService"
+ * @scr.reference name="user.realmservice.default"
+ * interface="org.wso2.carbon.user.core.service.RealmService"
+ * cardinality="1..1" policy="dynamic" bind="setRealmService"
+ * unbind="unsetRealmService"
+ * @scr.reference name="configuration.context.service" interface="org.wso2.carbon.utils.ConfigurationContextService"
+ * cardinality="1..1" policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
+ *
+ */
+public class CommonServiceComponent {
+
+ private static Log log = LogFactory.getLog(CommonServiceComponent.class);
+
+ protected void activate(ComponentContext context) {
+ try {
+ final BundleContext bundleContext = context.getBundleContext();
+ if (CommonUtil.getStratosConfig() == null) {
+ StratosConfiguration stratosConfig = CommonUtil.loadStratosConfiguration();
+ CommonUtil.setStratosConfig(stratosConfig);
+ }
+
+ // Loading the EULA
+ if (CommonUtil.getEula() == null) {
+ String eula = CommonUtil.loadTermsOfUsage();
+ CommonUtil.setEula(eula);
+ }
+
+ AxisConfiguration axisConfig = ServiceReferenceHolder.getInstance().getAxisConfiguration();
+ if((axisConfig != null) && (axisConfig.getClusteringAgent() != null)) {
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ // Wait for the hazelcast instance to be available
+ long startTime = System.currentTimeMillis();
+ log.info("Waiting for the hazelcast instance to be initialized...");
+ while (ServiceReferenceHolder.getInstance().getHazelcastInstance() == null) {
+ Thread.sleep(1000);
+ if ((System.currentTimeMillis() - startTime) >= StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT) {
+ throw new RuntimeException("Hazelcast instance was not initialized within "
+ + StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT / 1000 + " seconds");
+ }
+ }
+ registerDistributedObjectProviderService(bundleContext);
+ registerComponentStartUpSynchronizer(bundleContext);
+
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+ };
+ thread.setName("Distributed object provider registration thread");
+ thread.start();
+ } else {
+ // Register distributed object provider service
+ registerDistributedObjectProviderService(bundleContext);
+ registerComponentStartUpSynchronizer(bundleContext);
+ }
+
+ // Register manager configuration service
+ try {
+ StratosConfiguration stratosConfiguration = CommonUtil.loadStratosConfiguration();
+ bundleContext.registerService(StratosConfiguration.class.getName(), stratosConfiguration, null);
+ } catch (Exception ex) {
+ String msg = "An error occurred while registering stratos configuration service";
+ log.error(msg, ex);
+ }
+
+ if (log.isInfoEnabled()) {
+ log.info("Stratos common service component is activated");
+ }
+ } catch (Exception e) {
+ log.error("Error in activating stratos common service component", e);
+ }
+ }
+
+ private void registerDistributedObjectProviderService(BundleContext bundleContext) {
+ DistributedObjectProvider distributedObjectProvider = new HazelcastDistributedObjectProvider();
+ ServiceReferenceHolder.getInstance().setDistributedObjectProvider(distributedObjectProvider);
+ bundleContext.registerService(DistributedObjectProvider.class, distributedObjectProvider, null);
+ }
+
+ private void registerComponentStartUpSynchronizer(BundleContext bundleContext) {
+ ComponentStartUpSynchronizer componentStartUpSynchronizer =
+ new ComponentStartUpSynchronizerImpl(
+ ServiceReferenceHolder.getInstance().getDistributedObjectProvider());
+ bundleContext.registerService(ComponentStartUpSynchronizer.class, componentStartUpSynchronizer, null);
+ }
+
+ protected void deactivate(ComponentContext context) {
+ log.debug("Stratos common service is deactivated");
+ }
+
+ protected void setRegistryService(RegistryService registryService) {
+ ServiceReferenceHolder.getInstance().setRegistryService(registryService);
+ }
+
+ protected void unsetRegistryService(RegistryService registryService) {
+ setRegistryService(null);
+ }
+
+ protected void setRealmService(RealmService realmService) {
+ ServiceReferenceHolder.getInstance().setRealmService(realmService);
+ }
+
+ protected void unsetRealmService(RealmService realmService) {
+ ServiceReferenceHolder.getInstance().setRealmService(null);
+ }
+
+ public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
+ ServiceReferenceHolder.getInstance().setHazelcastInstance(hazelcastInstance);
+ }
+
+ public void unsetHazelcastInstance(HazelcastInstance hazelcastInstance) {
+ ServiceReferenceHolder.getInstance().setHazelcastInstance(null);
+ }
+
+ protected void setDistributedMapProvider(DistributedMapProvider mapProvider) {
+ ServiceReferenceHolder.getInstance().setDistributedMapProvider(mapProvider);
+ }
+
+ protected void unsetDistributedMapProvider(DistributedMapProvider mapProvider) {
+ ServiceReferenceHolder.getInstance().setDistributedMapProvider(null);
+ }
+
+ protected void setConfigurationContextService(ConfigurationContextService cfgCtxService) {
+ ServiceReferenceHolder.getInstance().setAxisConfiguration(cfgCtxService.getServerConfigContext().getAxisConfiguration());
+ }
+
+ protected void unsetConfigurationContextService(ConfigurationContextService cfgCtxService) {
+ ServiceReferenceHolder.getInstance().setAxisConfiguration(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java
new file mode 100644
index 0000000..e0fff77
--- /dev/null
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java
@@ -0,0 +1,124 @@
+/*
+ * 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.common.internal;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.Component;
+import org.apache.stratos.common.services.ComponentStartUpSynchronizer;
+import org.apache.stratos.common.services.DistributedObjectProvider;
+import org.wso2.carbon.core.CarbonConfigurationContextFactory;
+
+import java.util.Map;
+
+/**
+ * Stratos component startup synchronizer.
+ */
+public class ComponentStartUpSynchronizerImpl implements ComponentStartUpSynchronizer {
+
+ private static final Log log = LogFactory.getLog(ComponentStartUpSynchronizerImpl.class);
+
+ private static final String COMPONENT_STATUS_MAP = "stratos.component.status.map";
+ private static final String COMPONENT_ACTIVATION_CHECK_INTERVAL = "stratos.component.activation.check.interval";
+ private static final String COMPONENT_ACTIVATION_TIMEOUT = "stratos.component.activation.timeout";
+ private static final long DEFAULT_COMPONENT_ACTIVATION_CHECK_INTERVAL = 5000;
+ private static final long DEFAULT_COMPONENT_ACTIVATION_TIMEOUT = 600000;
+
+ private Map<Component, Boolean> componentStatusMap;
+ private long componentActivationCheckInterval;
+ private long componentActivationTimeout;
+
+ ComponentStartUpSynchronizerImpl(DistributedObjectProvider distributedObjectProvider) {
+ componentStatusMap = distributedObjectProvider.getMap(COMPONENT_STATUS_MAP);
+
+ componentActivationCheckInterval = Long.getLong(COMPONENT_ACTIVATION_CHECK_INTERVAL,
+ DEFAULT_COMPONENT_ACTIVATION_CHECK_INTERVAL);
+ log.info(String.format("Component activation check interval: %s seconds",
+ (componentActivationCheckInterval/1000)));
+
+ componentActivationTimeout = Long.getLong(COMPONENT_ACTIVATION_TIMEOUT,
+ DEFAULT_COMPONENT_ACTIVATION_TIMEOUT);
+ log.info(String.format("Component activation timeout: %s seconds", (componentActivationTimeout/1000)));
+ }
+
+ @Override
+ public void setComponentStatus(Component component, boolean active) {
+ componentStatusMap.put(component, active);
+
+ if(active) {
+ log.info(String.format("%s component became active", component));
+ } else {
+ log.info(String.format("%s component became inactive", component));
+ }
+ }
+
+ @Override
+ public boolean isComponentActive(Component component) {
+ if(componentStatusMap.containsKey(component)) {
+ return componentStatusMap.get(component);
+ }
+ return false;
+ }
+
+ @Override
+ public void waitForComponentActivation(Component owner, Component component) {
+ long startTime = System.currentTimeMillis();
+ while(!isComponentActive(component)) {
+ log.info(String.format("%s component is waiting for %s component to become active...",
+ owner, component));
+
+ try {
+ Thread.sleep(componentActivationCheckInterval);
+ } catch (InterruptedException ignore) {
+ throw new RuntimeException(String.format("Thread interrupted, %s component could not wait for " +
+ "component %s to become active", owner, component));
+ }
+
+ long currentTime = System.currentTimeMillis();
+ if((currentTime - startTime) > componentActivationTimeout) {
+ throw new RuntimeException(String.format("%s component did not become active within %d seconds ",
+ component, (componentActivationTimeout/1000)));
+ }
+ }
+ }
+
+ @Override
+ public void waitForWebServiceActivation(String serviceName) throws AxisFault {
+ AxisConfiguration axisConfiguration = CarbonConfigurationContextFactory.getConfigurationContext()
+ .getAxisConfiguration();
+ AxisService cloudControllerService = axisConfiguration.getService(serviceName);
+ if(!cloudControllerService.isActive()) {
+ while (!cloudControllerService.isActive()) {
+ log.info(String.format("Waiting for %s web service to become active...", serviceName));
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ignore) {
+ return;
+ }
+ }
+ log.info(String.format("%s web service became active", serviceName));
+ } else {
+ log.debug(String.format("%s web service is active", serviceName));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ServiceReferenceHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ServiceReferenceHolder.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ServiceReferenceHolder.java
index ed51902..1e21975 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ServiceReferenceHolder.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ServiceReferenceHolder.java
@@ -4,6 +4,7 @@ import com.hazelcast.core.HazelcastInstance;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.services.DistributedObjectProvider;
import org.wso2.carbon.caching.impl.DistributedMapProvider;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
@@ -14,12 +15,14 @@ import org.wso2.carbon.user.core.service.RealmService;
public class ServiceReferenceHolder {
private static final Log log = LogFactory.getLog(ServiceReferenceHolder.class);
+
private static volatile ServiceReferenceHolder instance;
private HazelcastInstance hazelcastInstance;
private DistributedMapProvider distributedMapProvider;
private RealmService realmService;
private RegistryService registryService;
private AxisConfiguration axisConfiguration;
+ private DistributedObjectProvider distributedObjectProvider;
private ServiceReferenceHolder() {
}
@@ -75,4 +78,12 @@ public class ServiceReferenceHolder {
public AxisConfiguration getAxisConfiguration() {
return axisConfiguration;
}
+
+ public void setDistributedObjectProvider(DistributedObjectProvider distributedObjectProvider) {
+ this.distributedObjectProvider = distributedObjectProvider;
+ }
+
+ public DistributedObjectProvider getDistributedObjectProvider() {
+ return distributedObjectProvider;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
deleted file mode 100644
index 275128b..0000000
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/StratosCommonServiceComponent.java
+++ /dev/null
@@ -1,167 +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.common.internal;
-
-import com.hazelcast.core.HazelcastInstance;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.clustering.DistributedObjectProvider;
-import org.apache.stratos.common.clustering.impl.HazelcastDistributedObjectProvider;
-import org.apache.stratos.common.constants.StratosConstants;
-import org.apache.stratos.common.util.CommonUtil;
-import org.apache.stratos.common.util.StratosConfiguration;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.component.ComponentContext;
-import org.wso2.carbon.caching.impl.DistributedMapProvider;
-import org.wso2.carbon.registry.core.service.RegistryService;
-import org.wso2.carbon.user.core.service.RealmService;
-import org.wso2.carbon.utils.ConfigurationContextService;
-
-/**
- * @scr.component name="apache.stratos.common" immediate="true"
- * @scr.reference name="hazelcast.instance.service" interface="com.hazelcast.core.HazelcastInstance"
- * cardinality="0..1"policy="dynamic" bind="setHazelcastInstance" unbind="unsetHazelcastInstance"
- * @scr.reference name="distributedMapProvider" interface="org.wso2.carbon.caching.impl.DistributedMapProvider"
- * cardinality="0..1" policy="dynamic" bind="setDistributedMapProvider" unbind="unsetDistributedMapProvider"
- * @scr.reference name="registry.service"
- * interface="org.wso2.carbon.registry.core.service.RegistryService"
- * cardinality="1..1" policy="dynamic" bind="setRegistryService"
- * unbind="unsetRegistryService"
- * @scr.reference name="user.realmservice.default"
- * interface="org.wso2.carbon.user.core.service.RealmService"
- * cardinality="1..1" policy="dynamic" bind="setRealmService"
- * unbind="unsetRealmService"
- * @scr.reference name="configuration.context.service" interface="org.wso2.carbon.utils.ConfigurationContextService"
- * cardinality="1..1" policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
- *
- */
-public class StratosCommonServiceComponent {
-
- private static Log log = LogFactory.getLog(StratosCommonServiceComponent.class);
-
- protected void activate(ComponentContext context) {
- try {
- final BundleContext bundleContext = context.getBundleContext();
- if (CommonUtil.getStratosConfig() == null) {
- StratosConfiguration stratosConfig = CommonUtil.loadStratosConfiguration();
- CommonUtil.setStratosConfig(stratosConfig);
- }
-
- // Loading the EULA
- if (CommonUtil.getEula() == null) {
- String eula = CommonUtil.loadTermsOfUsage();
- CommonUtil.setEula(eula);
- }
-
- AxisConfiguration axisConfig = ServiceReferenceHolder.getInstance().getAxisConfiguration();
- if((axisConfig != null) && (axisConfig.getClusteringAgent() != null)) {
- Thread thread = new Thread() {
- @Override
- public void run() {
- try {
- // Wait for the hazelcast instance to be available
- long startTime = System.currentTimeMillis();
- log.info("Waiting for the hazelcast instance to be initialized...");
- while (ServiceReferenceHolder.getInstance().getHazelcastInstance() == null) {
- Thread.sleep(1000);
- if ((System.currentTimeMillis() - startTime) >= StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT) {
- throw new RuntimeException("Hazelcast instance was not initialized within "
- + StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT / 1000 + " seconds");
- }
- }
- registerDistributedObjectProviderService(bundleContext);
- } catch (Exception e) {
- log.error(e);
- }
- }
- };
- thread.setName("Distributed object provider registration thread");
- thread.start();
- } else {
- // Register distributed object provider service
- registerDistributedObjectProviderService(bundleContext);
- }
-
- // Register manager configuration service
- try {
- StratosConfiguration stratosConfiguration = CommonUtil.loadStratosConfiguration();
- bundleContext.registerService(StratosConfiguration.class.getName(), stratosConfiguration, null);
- } catch (Exception ex) {
- String msg = "An error occurred while registering stratos configuration service";
- log.error(msg, ex);
- }
-
- if (log.isInfoEnabled()) {
- log.info("Stratos common service component is activated");
- }
- } catch (Exception e) {
- log.error("Error in activating stratos common service component", e);
- }
- }
-
- private void registerDistributedObjectProviderService(BundleContext bundleContext) {
- DistributedObjectProvider distributedObjectProvider = new HazelcastDistributedObjectProvider();
- bundleContext.registerService(DistributedObjectProvider.class, distributedObjectProvider, null);
- }
-
- protected void deactivate(ComponentContext context) {
- log.debug("Stratos common service is deactivated");
- }
-
- protected void setRegistryService(RegistryService registryService) {
- ServiceReferenceHolder.getInstance().setRegistryService(registryService);
- }
-
- protected void unsetRegistryService(RegistryService registryService) {
- setRegistryService(null);
- }
-
- protected void setRealmService(RealmService realmService) {
- ServiceReferenceHolder.getInstance().setRealmService(realmService);
- }
-
- protected void unsetRealmService(RealmService realmService) {
- ServiceReferenceHolder.getInstance().setRealmService(null);
- }
-
- public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
- ServiceReferenceHolder.getInstance().setHazelcastInstance(hazelcastInstance);
- }
-
- public void unsetHazelcastInstance(HazelcastInstance hazelcastInstance) {
- ServiceReferenceHolder.getInstance().setHazelcastInstance(null);
- }
-
- protected void setDistributedMapProvider(DistributedMapProvider mapProvider) {
- ServiceReferenceHolder.getInstance().setDistributedMapProvider(mapProvider);
- }
-
- protected void unsetDistributedMapProvider(DistributedMapProvider mapProvider) {
- ServiceReferenceHolder.getInstance().setDistributedMapProvider(null);
- }
-
- protected void setConfigurationContextService(ConfigurationContextService cfgCtxService) {
- ServiceReferenceHolder.getInstance().setAxisConfiguration(cfgCtxService.getServerConfigContext().getAxisConfiguration());
- }
-
- protected void unsetConfigurationContextService(ConfigurationContextService cfgCtxService) {
- ServiceReferenceHolder.getInstance().setAxisConfiguration(null);
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java
new file mode 100644
index 0000000..e584237
--- /dev/null
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java
@@ -0,0 +1,37 @@
+/*
+ * 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.common.services;
+
+import org.apache.axis2.AxisFault;
+import org.apache.stratos.common.Component;
+
+/**
+ * Component startup synchronizer service interface.
+ */
+public interface ComponentStartUpSynchronizer {
+
+ void setComponentStatus(Component component, boolean active);
+
+ boolean isComponentActive(Component component);
+
+ void waitForComponentActivation(Component owner, Component component);
+
+ void waitForWebServiceActivation(String serviceName) throws AxisFault;
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/DistributedObjectProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/DistributedObjectProvider.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/DistributedObjectProvider.java
new file mode 100644
index 0000000..2c013bd
--- /dev/null
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/DistributedObjectProvider.java
@@ -0,0 +1,73 @@
+/*
+ * 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.common.services;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+
+/**
+ * Distributed object provider service interface.
+ * Caution! When using distributed maps and lists, please note that changes done to an item in a map/list
+ * after adding them to the map/list will not be replicated in the cluster. If a modification of an item
+ * needs to be replicated, that item needs to be put() to the map or set() back in the list.
+ */
+public interface DistributedObjectProvider extends Serializable {
+ /**
+ * Returns a distributed map if clustering is enabled, else returns a local hash map.
+ * @param name
+ * @return
+ */
+ Map getMap(String name);
+
+ /**
+ * Removes a map from the object provider.
+ * @param name
+ */
+ void removeMap(String name);
+
+ /**
+ * Returns a distributed list if clustering is enabled, else returns a local array list.
+ * @param name
+ * @return
+ */
+ List getList(String name);
+
+ /**
+ * Remove a list from the object provider.
+ * @param name
+ */
+ void removeList(String name);
+
+ /**
+ * Acquires a distributed lock if clustering is enabled, else acquires a local reentrant lock and
+ * returns the lock object.
+ * @param object
+ * @return
+ */
+ Lock acquireLock(Object object);
+
+ /**
+ * Releases a given distributed/local lock.
+ * @param lock
+ */
+ void releaseLock(Lock lock);
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/PackageInfoService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/PackageInfoService.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/PackageInfoService.java
deleted file mode 100644
index 82c0e86..0000000
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/PackageInfoService.java
+++ /dev/null
@@ -1,35 +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.common.services;
-
-import org.apache.stratos.common.internal.StratosCommonServiceComponent;
-import org.apache.stratos.common.packages.PackageInfo;
-
-import java.util.List;
-
-
-public class PackageInfoService {
-
-// public PackageInfo[] getPackageInfos() throws Exception {
-// List<PackageInfo> list = StratosCommonServiceComponent.getPackageInfos().
-// getMultitenancyPackages();
-// PackageInfo[] packageInfos = list.toArray(new PackageInfo[list.size()]);
-// return packageInfos;
-// }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CommonUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CommonUtil.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CommonUtil.java
index 436eb2a..b49c42d 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CommonUtil.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CommonUtil.java
@@ -25,7 +25,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.common.constants.StratosConstants;
import org.apache.stratos.common.internal.ServiceReferenceHolder;
-import org.apache.stratos.common.internal.StratosCommonServiceComponent;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.registry.core.ActionConstants;
import org.wso2.carbon.registry.core.RegistryConstants;
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/AlgorithmContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/AlgorithmContext.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/AlgorithmContext.java
index 365cfc4..d261791 100755
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/AlgorithmContext.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/AlgorithmContext.java
@@ -19,7 +19,7 @@
package org.apache.stratos.load.balancer.context;
-import org.apache.stratos.common.clustering.DistributedObjectProvider;
+import org.apache.stratos.common.services.DistributedObjectProvider;
import org.apache.stratos.load.balancer.internal.ServiceReferenceHolder;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
index 2532d96..ca055de 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
@@ -24,7 +24,7 @@ import org.apache.axis2.deployment.DeploymentEngine;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.clustering.DistributedObjectProvider;
+import org.apache.stratos.common.services.DistributedObjectProvider;
import org.apache.stratos.common.threading.StratosThreadPool;
import org.apache.stratos.load.balancer.common.event.receivers.LoadBalancerCommonApplicationSignUpEventReceiver;
import org.apache.stratos.load.balancer.common.statistics.notifier.LoadBalancerStatisticsNotifier;
@@ -67,7 +67,7 @@ import java.util.concurrent.ExecutorService;
/**
* @scr.component name="org.apache.stratos.load.balancer.internal.LoadBalancerServiceComponent" immediate="true"
- * @scr.reference name="distributedObjectProvider" interface="org.apache.stratos.common.clustering.DistributedObjectProvider"
+ * @scr.reference name="distributedObjectProvider" interface="org.apache.stratos.common.services.DistributedObjectProvider"
* cardinality="1..1" policy="dynamic" bind="setDistributedObjectProvider" unbind="unsetDistributedObjectProvider"
* @scr.reference name="configuration.context.service" interface="org.wso2.carbon.utils.ConfigurationContextService"
* cardinality="1..1" policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
index e026ac5..cae9bec 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
@@ -23,7 +23,7 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.clustering.DistributedObjectProvider;
+import org.apache.stratos.common.services.DistributedObjectProvider;
import org.apache.stratos.load.balancer.exception.TenantAwareLoadBalanceEndpointException;
import org.apache.synapse.config.SynapseConfiguration;
import org.wso2.carbon.mediation.dependency.mgt.services.DependencyManagementService;
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/context/StratosManagerContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/context/StratosManagerContext.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/context/StratosManagerContext.java
index 8841b46..44d44d9 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/context/StratosManagerContext.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/context/StratosManagerContext.java
@@ -20,9 +20,7 @@
package org.apache.stratos.manager.context;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
@@ -31,7 +29,7 @@ import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.manager.registry.RegistryManager;
-import org.apache.stratos.common.clustering.DistributedObjectProvider;
+import org.apache.stratos.common.services.DistributedObjectProvider;
import org.apache.stratos.manager.internal.ServiceReferenceHolder;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ServiceReferenceHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ServiceReferenceHolder.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ServiceReferenceHolder.java
index 4c3d9a5..221891d 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ServiceReferenceHolder.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ServiceReferenceHolder.java
@@ -22,7 +22,8 @@ package org.apache.stratos.manager.internal;
import com.hazelcast.core.HazelcastInstance;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.stratos.common.clustering.DistributedObjectProvider;
+import org.apache.stratos.common.services.ComponentStartUpSynchronizer;
+import org.apache.stratos.common.services.DistributedObjectProvider;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
@@ -42,6 +43,7 @@ public class ServiceReferenceHolder {
private HazelcastInstance hazelcastInstance;
private AxisConfiguration axisConfiguration;
private DistributedObjectProvider distributedObjectProvider;
+ private ComponentStartUpSynchronizer componentStartUpSynchronizer;
private ServiceReferenceHolder() { }
@@ -121,5 +123,12 @@ public class ServiceReferenceHolder {
public DistributedObjectProvider getDistributedObjectProvider() {
return distributedObjectProvider;
}
-
+
+ public void setComponentStartUpSynchronizer(ComponentStartUpSynchronizer componentStartUpSynchronizer) {
+ this.componentStartUpSynchronizer = componentStartUpSynchronizer;
+ }
+
+ public ComponentStartUpSynchronizer getComponentStartUpSynchronizer() {
+ return componentStartUpSynchronizer;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/StratosManagerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/StratosManagerServiceComponent.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/StratosManagerServiceComponent.java
index 2830bf1..cd3215c 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/StratosManagerServiceComponent.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/StratosManagerServiceComponent.java
@@ -18,11 +18,12 @@
*/
package org.apache.stratos.manager.internal;
-import java.util.concurrent.ExecutorService;
-
+import com.hazelcast.core.HazelcastInstance;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.clustering.DistributedObjectProvider;
+import org.apache.stratos.common.Component;
+import org.apache.stratos.common.services.ComponentStartUpSynchronizer;
+import org.apache.stratos.common.services.DistributedObjectProvider;
import org.apache.stratos.common.threading.StratosThreadPool;
import org.apache.stratos.manager.context.StratosManagerContext;
import org.apache.stratos.manager.messaging.publisher.TenantEventPublisher;
@@ -48,7 +49,7 @@ import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService;
-import com.hazelcast.core.HazelcastInstance;
+import java.util.concurrent.ExecutorService;
/**
* @scr.component name="org.wso2.carbon.hosting.mgt.internal.StratosManagerServiceComponent"
@@ -71,8 +72,10 @@ import com.hazelcast.core.HazelcastInstance;
* @scr.reference name="ntask.component" interface="org.wso2.carbon.ntask.core.service.TaskService"
* cardinality="1..1" policy="dynamic" bind="setTaskService"
* unbind="unsetTaskService"
- * @scr.reference name="distributedObjectProvider" interface="org.apache.stratos.common.clustering.DistributedObjectProvider"
+ * @scr.reference name="distributedObjectProvider" interface="org.apache.stratos.common.services.DistributedObjectProvider"
* cardinality="1..1" policy="dynamic" bind="setDistributedObjectProvider" unbind="unsetDistributedObjectProvider"
+ * @scr.reference name="componentStartUpSynchronizer" interface="org.apache.stratos.common.services.ComponentStartUpSynchronizer"
+ * cardinality="1..1" policy="dynamic" bind="setComponentStartUpSynchronizer" unbind="unsetComponentStartUpSynchronizer"
*/
public class StratosManagerServiceComponent {
@@ -88,46 +91,67 @@ public class StratosManagerServiceComponent {
protected void activate(final ComponentContext componentContext) throws Exception {
try {
- CartridgeConfigFileReader.readProperties();
- executorService = StratosThreadPool.getExecutorService(THREAD_EXECUTOR_ID, THREAD_POOL_SIZE);
-
- if(StratosManagerContext.getInstance().isClustered()) {
- Thread coordinatorElectorThread = new Thread() {
- @Override
- public void run() {
- try {
- ServiceReferenceHolder.getInstance().getHazelcastInstance()
- .getLock(STRATOS_MANAGER_COORDINATOR_LOCK).lock();
-
- String localMemberId = ServiceReferenceHolder.getInstance().getHazelcastInstance()
- .getCluster().getLocalMember().getUuid();
- log.info("Elected this member [" + localMemberId + "] " +
- "as the stratos manager coordinator for the cluster");
-
- StratosManagerContext.getInstance().setCoordinator(true);
+ executorService = StratosThreadPool.getExecutorService(THREAD_EXECUTOR_ID, THREAD_POOL_SIZE);
+ Runnable stratosManagerActivator = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ ComponentStartUpSynchronizer componentStartUpSynchronizer =
+ ServiceReferenceHolder.getInstance().getComponentStartUpSynchronizer();
+
+ // Wait for cloud controller and autoscaler components to start
+ componentStartUpSynchronizer.waitForComponentActivation(Component.StratosManager,
+ Component.CloudController);
+ componentStartUpSynchronizer.waitForComponentActivation(Component.StratosManager,
+ Component.Autoscaler);
+
+ CartridgeConfigFileReader.readProperties();
+ if (StratosManagerContext.getInstance().isClustered()) {
+ Thread coordinatorElectorThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ ServiceReferenceHolder.getInstance().getHazelcastInstance()
+ .getLock(STRATOS_MANAGER_COORDINATOR_LOCK).lock();
+
+ String localMemberId = ServiceReferenceHolder.getInstance().getHazelcastInstance()
+ .getCluster().getLocalMember().getUuid();
+ log.info("Elected this member [" + localMemberId + "] " +
+ "as the stratos manager coordinator for the cluster");
+
+ StratosManagerContext.getInstance().setCoordinator(true);
+ executeCoordinatorTasks(componentContext);
+ } catch (Exception e) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not execute coordinator tasks", e);
+ }
+ }
+ }
+ };
+ coordinatorElectorThread.setName("Stratos manager coordinator elector thread");
+ executorService.submit(coordinatorElectorThread);
+ } else {
executeCoordinatorTasks(componentContext);
- } catch (Exception e) {
- if(log.isErrorEnabled()) {
- log.error("Could not execute coordinator tasks", e);
- }
}
+
+ // Initialize topology event receiver
+ initializeTopologyEventReceiver();
+
+ // Initialize application event receiver
+ initializeApplicationEventReceiver();
+
+ componentStartUpSynchronizer.waitForWebServiceActivation("StratosManagerService");
+ componentStartUpSynchronizer.setComponentStatus(Component.StratosManager, true);
+ if (log.isInfoEnabled()) {
+ log.info("Stratos manager component is activated");
+ }
+ } catch (Exception e) {
+ log.error("Could not activate stratos manager service component", e);
}
- };
- coordinatorElectorThread.setName("Stratos manager coordinator elector thread");
- executorService.submit(coordinatorElectorThread);
- } else {
- executeCoordinatorTasks(componentContext);
- }
-
- // Initialize topology event receiver
- initializeTopologyEventReceiver();
-
- // Initialize application event receiver
- initializeApplicationEventReceiver();
-
- if(log.isInfoEnabled()) {
- log.info("Stratos manager component is activated");
- }
+ }
+ };
+ Thread stratosManagerActivatorThread = new Thread(stratosManagerActivator);
+ stratosManagerActivatorThread.start();
} catch (Exception e) {
log.error("Could not activate stratos manager service component", e);
}
@@ -290,6 +314,14 @@ public class StratosManagerServiceComponent {
ServiceReferenceHolder.getInstance().setDistributedObjectProvider(null);
}
+ protected void setComponentStartUpSynchronizer(ComponentStartUpSynchronizer componentStartUpSynchronizer) {
+ ServiceReferenceHolder.getInstance().setComponentStartUpSynchronizer(componentStartUpSynchronizer);
+ }
+
+ protected void unsetComponentStartUpSynchronizer(ComponentStartUpSynchronizer componentStartUpSynchronizer) {
+ ServiceReferenceHolder.getInstance().setComponentStartUpSynchronizer(null);
+ }
+
protected void deactivate(ComponentContext context) {
// Close event publisher connections to message broker
EventPublisherPool.close(MessagingUtil.Topics.INSTANCE_NOTIFIER_TOPIC.getTopicName());
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/handlers/ComponentSynchronizerHandler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/handlers/ComponentSynchronizerHandler.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/handlers/ComponentSynchronizerHandler.java
new file mode 100644
index 0000000..b7456e4
--- /dev/null
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/handlers/ComponentSynchronizerHandler.java
@@ -0,0 +1,47 @@
+/*
+ * 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.rest.endpoint.handlers;
+
+import org.apache.cxf.jaxrs.ext.RequestHandler;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.message.Message;
+import org.apache.stratos.common.Component;
+import org.apache.stratos.common.beans.ApiResponseBean;
+import org.apache.stratos.common.services.ComponentStartUpSynchronizer;
+import org.apache.stratos.manager.internal.ServiceReferenceHolder;
+
+import javax.ws.rs.core.Response;
+
+/**
+ * Component synchronizer handler for enabling rest api once stratos manager component becomes active.
+ */
+public class ComponentSynchronizerHandler implements RequestHandler {
+
+ public Response handleRequest(Message message, ClassResourceInfo classResourceInfo) {
+ ComponentStartUpSynchronizer componentStartUpSynchronizer =
+ ServiceReferenceHolder.getInstance().getComponentStartUpSynchronizer();
+ if(!componentStartUpSynchronizer.isComponentActive(Component.StratosManager)) {
+ ApiResponseBean responseBean = new ApiResponseBean();
+ responseBean.setMessage("Stratos manager component is not active");
+ return Response.status(Response.Status.NOT_ACCEPTABLE).entity(responseBean).build();
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.rest.endpoint/src/main/webapp/api-test/WEB-INF/cxf-servlet.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/webapp/api-test/WEB-INF/cxf-servlet.xml b/components/org.apache.stratos.rest.endpoint/src/main/webapp/api-test/WEB-INF/cxf-servlet.xml
index 8952d7e..fdecda7 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/webapp/api-test/WEB-INF/cxf-servlet.xml
+++ b/components/org.apache.stratos.rest.endpoint/src/main/webapp/api-test/WEB-INF/cxf-servlet.xml
@@ -53,6 +53,7 @@
<bean id="badRequestExceptionHandler" class="org.apache.stratos.rest.endpoint.handlers.BadRequestExceptionMapper"/>
<bean id="genericExceptionHandler" class="org.apache.stratos.rest.endpoint.handlers.GenericExceptionMapper"/>
<bean id="throwableExceptionHandler" class="org.apache.stratos.rest.endpoint.handlers.CustomThrowableExceptionMapper"/>
+ <bean id="componentSynrhronizerHandler" class="org.apache.stratos.rest.endpoint.handlers.ComponentSynchronizerHandler"/>
<!--The below config enables OAuth based authentication/authorization for REST API-->
<bean id="OAuthFilter" class="org.apache.stratos.rest.endpoint.handlers.OAuthHandler">
<property name="password" value="admin"/>
http://git-wip-us.apache.org/repos/asf/stratos/blob/c6e8359d/components/org.apache.stratos.rest.endpoint/src/main/webapp/api/WEB-INF/cxf-servlet.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/webapp/api/WEB-INF/cxf-servlet.xml b/components/org.apache.stratos.rest.endpoint/src/main/webapp/api/WEB-INF/cxf-servlet.xml
index e326d79..3e6aa55 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/webapp/api/WEB-INF/cxf-servlet.xml
+++ b/components/org.apache.stratos.rest.endpoint/src/main/webapp/api/WEB-INF/cxf-servlet.xml
@@ -38,6 +38,7 @@
<ref bean="badRequestExceptionHandler"/>
<ref bean="jsonProvider"/>
<ref bean="exceptionHandler"/>
+ <ref bean="componentSynchronizerHandler"/>
<ref bean="basicAuthenticationFilter"/>
<ref bean="sessionAuthenticationFilter"/>
<ref bean="authorizationFilterV41"/>
@@ -55,6 +56,7 @@
<ref bean="badRequestExceptionHandler"/>
<ref bean="jsonProvider"/>
<ref bean="exceptionHandler"/>
+ <ref bean="componentSynchronizerHandler"/>
<ref bean="basicAuthenticationFilter"/>
<ref bean="sessionAuthenticationFilter"/>
<ref bean="authorizationFilterV40"/>
@@ -72,6 +74,7 @@
<ref bean="badRequestExceptionHandler"/>
<ref bean="jsonProvider"/>
<ref bean="exceptionHandler"/>
+ <ref bean="componentSynchronizerHandler"/>
<ref bean="basicAuthenticationFilter"/>
<ref bean="sessionAuthenticationFilter"/>
<ref bean="authorizationFilterV41"/>
@@ -92,6 +95,7 @@
<bean id="badRequestExceptionHandler" class="org.apache.stratos.rest.endpoint.handlers.BadRequestExceptionMapper"/>
<bean id="genericExceptionHandler" class="org.apache.stratos.rest.endpoint.handlers.GenericExceptionMapper"/>
<bean id="throwableExceptionHandler" class="org.apache.stratos.rest.endpoint.handlers.CustomThrowableExceptionMapper"/>
+ <bean id="componentSynchronizerHandler" class="org.apache.stratos.rest.endpoint.handlers.ComponentSynchronizerHandler"/>
<!--The below config enables OAuth based authentication/authorization for REST API-->
<bean id="OAuthFilter" class="org.apache.stratos.rest.endpoint.handlers.OAuthHandler">
<property name="password" value="admin"/>