Repository: stratos Updated Branches: refs/heads/stratos-4.1.x a62c8ce79 -> 5c63e9302
fixing STRATOS-1614 & STRATOS-1615 Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5c63e930 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5c63e930 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5c63e930 Branch: refs/heads/stratos-4.1.x Commit: 5c63e93026c580b373dbb513c1ae1c0668205933 Parents: a62c8ce Author: rajkumar <[email protected]> Authored: Fri Nov 13 19:24:37 2015 +0530 Committer: rajkumar <[email protected]> Committed: Fri Nov 13 19:24:37 2015 +0530 ---------------------------------------------------------------------- .../internal/AutoscalerServiceComponent.java | 34 ++++---- .../common/util/CartridgeConfigFileReader.java | 87 ++++++++++++++++++++ .../StratosManagerServiceComponent.java | 2 +- .../utils/CartridgeConfigFileReader.java | 87 -------------------- 4 files changed, 108 insertions(+), 102 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/5c63e930/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java index 5011dd2..76844a0 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java @@ -48,6 +48,7 @@ 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.common.util.CartridgeConfigFileReader; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.registry.api.RegistryException; @@ -114,7 +115,7 @@ public class AutoscalerServiceComponent { .waitForComponentActivation(Component.Autoscaler, Component.CloudController); ServiceReferenceHolder.getInstance().setExecutorService(executorService); - + CartridgeConfigFileReader.readProperties(); if (AutoscalerContext.getInstance().isClustered()) { Thread coordinatorElectorThread = new Thread() { @Override @@ -161,6 +162,15 @@ public class AutoscalerServiceComponent { throws InvalidPolicyException, InvalidDeploymentPolicyException, InvalidApplicationPolicyException, AutoScalingPolicyAlreadyExistException { + syncInMemoryWithRegistry(); + + //starting the processor chain + ClusterStatusProcessorChain clusterStatusProcessorChain = new ClusterStatusProcessorChain(); + ServiceReferenceHolder.getInstance().setClusterStatusProcessorChain(clusterStatusProcessorChain); + + GroupStatusProcessorChain groupStatusProcessorChain = new GroupStatusProcessorChain(); + ServiceReferenceHolder.getInstance().setGroupStatusProcessorChain(groupStatusProcessorChain); + // Start topology receiver asTopologyReceiver = new AutoscalerTopologyEventReceiver(); asTopologyReceiver.setExecutorService(executorService); @@ -185,6 +195,15 @@ public class AutoscalerServiceComponent { log.debug("Initializer receiver thread started"); } + if (log.isInfoEnabled()) { + log.info("Scheduling tasks to publish applications"); + } + Runnable applicationSynchronizer = new ApplicationEventSynchronizer(); + scheduler.scheduleAtFixedRate(applicationSynchronizer, 0, 1, TimeUnit.MINUTES); + } + + private void syncInMemoryWithRegistry() throws AutoScalingPolicyAlreadyExistException, + InvalidDeploymentPolicyException, InvalidApplicationPolicyException { // Add AS policies to information model List<AutoscalePolicy> asPolicies = RegistryManager.getInstance().retrieveASPolicies(); Iterator<AutoscalePolicy> asPolicyIterator = asPolicies.iterator(); @@ -223,19 +242,6 @@ public class AutoscalerServiceComponent { //Adding application context from registry AutoscalerUtil.readApplicationContextsFromRegistry(); - - //starting the processor chain - ClusterStatusProcessorChain clusterStatusProcessorChain = new ClusterStatusProcessorChain(); - ServiceReferenceHolder.getInstance().setClusterStatusProcessorChain(clusterStatusProcessorChain); - - GroupStatusProcessorChain groupStatusProcessorChain = new GroupStatusProcessorChain(); - ServiceReferenceHolder.getInstance().setGroupStatusProcessorChain(groupStatusProcessorChain); - - if (log.isInfoEnabled()) { - log.info("Scheduling tasks to publish applications"); - } - Runnable applicationSynchronizer = new ApplicationEventSynchronizer(); - scheduler.scheduleAtFixedRate(applicationSynchronizer, 0, 1, TimeUnit.MINUTES); } protected void deactivate(ComponentContext context) { http://git-wip-us.apache.org/repos/asf/stratos/blob/5c63e930/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CartridgeConfigFileReader.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CartridgeConfigFileReader.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CartridgeConfigFileReader.java new file mode 100644 index 0000000..17ef5cc --- /dev/null +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/util/CartridgeConfigFileReader.java @@ -0,0 +1,87 @@ +/* + * 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.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.utils.CarbonUtils; +import org.wso2.securevault.SecretResolver; +import org.wso2.securevault.SecretResolverFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.util.Properties; + +public class CartridgeConfigFileReader { + + private static final Log log = LogFactory.getLog(CartridgeConfigFileReader.class); + private static String carbonHome = CarbonUtils.getCarbonHome(); + + /** + * Reads cartridge-config.properties file and assign properties to system + * properties + */ + public static void readProperties() { + + Properties properties = new Properties(); + try { + properties.load(new FileInputStream(carbonHome + File.separator + "repository" + + File.separator + "conf" + File.separator + + "cartridge-config.properties")); + } catch (Exception e) { + log.error("Exception is occurred in reading properties file. Reason:" + e.getMessage()); + } + if (log.isInfoEnabled()) { + log.info("Setting config properties into System properties"); + } + + if (log.isDebugEnabled()) { + log.debug("Start reading properties and set it as system properties"); + } + SecretResolver secretResolver = SecretResolverFactory.create(properties); + for (String name : properties.stringPropertyNames()) { + String value = properties.getProperty(name); + if (log.isDebugEnabled()) { + log.debug(" >>> Property Name :" + name + " Property Value :" + value); + } + if (value.equalsIgnoreCase("secretAlias:" + name)) { + if (log.isDebugEnabled()) { + log.debug("Secret Alias Found : " + name); + } + if (secretResolver != null && secretResolver.isInitialized()) { + if (log.isDebugEnabled()) { + log.debug("SecretResolver is initialized "); + } + if (secretResolver.isTokenProtected(name)) { + if (log.isDebugEnabled()) { + log.debug("SecretResolver [" + name + "] is token protected"); + } + value = secretResolver.resolve(name); + if (log.isDebugEnabled()) { + log.debug("SecretResolver [" + name + "] is decrypted properly"); + } + } + } + } + + System.setProperty(name, value); + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/5c63e930/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 bd09d7e..8b464ea 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 @@ -35,7 +35,7 @@ import org.apache.stratos.manager.messaging.receiver.StratosManagerInstanceStatu import org.apache.stratos.manager.messaging.receiver.StratosManagerTopologyEventReceiver; import org.apache.stratos.manager.user.management.TenantUserRoleManager; import org.apache.stratos.manager.user.management.exception.UserManagerException; -import org.apache.stratos.manager.utils.CartridgeConfigFileReader; +import org.apache.stratos.common.util.CartridgeConfigFileReader; import org.apache.stratos.manager.utils.UserRoleCreator; import org.apache.stratos.messaging.broker.publish.EventPublisherPool; import org.apache.stratos.messaging.util.MessagingUtil; http://git-wip-us.apache.org/repos/asf/stratos/blob/5c63e930/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConfigFileReader.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConfigFileReader.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConfigFileReader.java deleted file mode 100644 index ab25406..0000000 --- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConfigFileReader.java +++ /dev/null @@ -1,87 +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.manager.utils; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.utils.CarbonUtils; -import org.wso2.securevault.SecretResolver; -import org.wso2.securevault.SecretResolverFactory; - -import java.io.File; -import java.io.FileInputStream; -import java.util.Properties; - -public class CartridgeConfigFileReader { - - private static final Log log = LogFactory.getLog(CartridgeConfigFileReader.class); - private static String carbonHome = CarbonUtils.getCarbonHome(); - - /** - * Reads cartridge-config.properties file and assign properties to system - * properties - */ - public static void readProperties() { - - Properties properties = new Properties(); - try { - properties.load(new FileInputStream(carbonHome + File.separator + "repository" + - File.separator + "conf" + File.separator + - "cartridge-config.properties")); - } catch (Exception e) { - log.error("Exception is occurred in reading properties file. Reason:" + e.getMessage()); - } - if (log.isInfoEnabled()) { - log.info("Setting config properties into System properties"); - } - - if (log.isDebugEnabled()) { - log.debug("Start reading properties and set it as system properties"); - } - SecretResolver secretResolver = SecretResolverFactory.create(properties); - for (String name : properties.stringPropertyNames()) { - String value = properties.getProperty(name); - if (log.isDebugEnabled()) { - log.debug(" >>> Property Name :" + name + " Property Value :" + value); - } - if (value.equalsIgnoreCase("secretAlias:" + name)) { - if (log.isDebugEnabled()) { - log.debug("Secret Alias Found : " + name); - } - if (secretResolver != null && secretResolver.isInitialized()) { - if (log.isDebugEnabled()) { - log.debug("SecretResolver is initialized "); - } - if (secretResolver.isTokenProtected(name)) { - if (log.isDebugEnabled()) { - log.debug("SecretResolver [" + name + "] is token protected"); - } - value = secretResolver.resolve(name); - if (log.isDebugEnabled()) { - log.debug("SecretResolver [" + name + "] is decrypted properly"); - } - } - } - } - - System.setProperty(name, value); - } - } -}
