Repository: stratos Updated Branches: refs/heads/docker-grouping-merge 62d65fd73 -> 070f950b7
publish to metadata service when applicaiton is parsed Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/bcf2e2b6 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/bcf2e2b6 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/bcf2e2b6 Branch: refs/heads/docker-grouping-merge Commit: bcf2e2b6c515764eba4a67505fe4956d077a4950 Parents: c1e557b Author: Udara Liyanage <[email protected]> Authored: Tue Nov 4 15:44:49 2014 +0530 Committer: Udara Liyanage <[email protected]> Committed: Tue Nov 4 15:44:49 2014 +0530 ---------------------------------------------------------------------- .../org.apache.stratos.autoscaler/pom.xml | 332 ++++++++++--------- .../autoscaler/api/AutoScalerServiceImpl.java | 29 +- .../applications/parser/ApplicationParser.java | 4 + .../parser/DefaultApplicationParser.java | 79 ++++- 4 files changed, 266 insertions(+), 178 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/bcf2e2b6/components/org.apache.stratos.autoscaler/pom.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/pom.xml b/components/org.apache.stratos.autoscaler/pom.xml index 64ad76a..394784e 100644 --- a/components/org.apache.stratos.autoscaler/pom.xml +++ b/components/org.apache.stratos.autoscaler/pom.xml @@ -18,140 +18,141 @@ under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.stratos</groupId> - <artifactId>stratos-components-parent</artifactId> - <version>4.1.0-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.apache.stratos</groupId> + <artifactId>stratos-components-parent</artifactId> + <version>4.1.0-SNAPSHOT</version> + </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>org.apache.stratos.autoscaler</artifactId> - <packaging>bundle</packaging> - <name>Apache Stratos - Autoscaler</name> - <description>Autoscaler components</description> - <url>http://apache.org</url> + <modelVersion>4.0.0</modelVersion> + <artifactId>org.apache.stratos.autoscaler</artifactId> + <packaging>bundle</packaging> + <name>Apache Stratos - Autoscaler</name> + <description>Autoscaler components</description> + <url>http://apache.org</url> - <dependencies> - <dependency> - <groupId>org.wso2.carbon</groupId> - <artifactId>org.wso2.carbon.registry.core</artifactId> - <version>${carbon.platform.version}</version> - <scope>provided</scope> - </dependency> + <dependencies> + <dependency> + <groupId>org.wso2.carbon</groupId> + <artifactId>org.wso2.carbon.registry.core</artifactId> + <version>${carbon.platform.version}</version> + <scope>provided</scope> + </dependency> - <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-core</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-compiler</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>com.thoughtworks.xstream</groupId> - <artifactId>xstream</artifactId> - <version>1.4.1</version> - </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-core</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-compiler</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>com.thoughtworks.xstream</groupId> + <artifactId>xstream</artifactId> + <version>1.4.1</version> + </dependency> <dependency> <groupId>commons-configuration</groupId> <artifactId>commons-configuration</artifactId> <version>1.9</version> </dependency> - <dependency> - <groupId>org.antlr</groupId> - <artifactId>antlr</artifactId> - <version>3.3</version> - </dependency> - <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-decisiontables</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>org.antlr</groupId> - <artifactId>antlr-runtime</artifactId> - <version>3.3</version> - </dependency> - <dependency> - <groupId>org.antlr</groupId> - <artifactId>stringtemplate</artifactId> - <version>3.2.1</version> - </dependency> - <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-jsr94</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>org.drools</groupId> - <artifactId>knowledge-internal-api</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>org.drools</groupId> - <artifactId>knowledge-api</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>org.mvel</groupId> - <artifactId>mvel2</artifactId> - <version>2.1.3.Final</version> - </dependency> - <!--dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.6.4</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.6.4</version> - </dependency--> - <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-verifier</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>org.drools</groupId> - <artifactId>drools-templates</artifactId> - <version>${drools.version}</version> - </dependency> - <dependency> - <groupId>org.eclipse.jdt.core.compiler</groupId> - <artifactId>ecj</artifactId> - <version>3.5.1</version> - </dependency> - <dependency> - <groupId>xmlpull</groupId> - <artifactId>xmlpull</artifactId> - <version>1.1.3.1</version> - </dependency> - <dependency> - <groupId>xpp3</groupId> - <artifactId>xpp3_min</artifactId> - <version>1.1.4c</version> - </dependency> - <dependency> - <groupId>com.lowagie</groupId> - <artifactId>itext</artifactId> - <version>2.1.2</version> - </dependency> - <dependency> - <groupId>jsr94</groupId> - <artifactId>jsr94</artifactId> - <version>1.1</version> - </dependency> - <dependency> - <groupId>org.apache.stratos</groupId> - <artifactId>org.apache.stratos.messaging</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> + <dependency> + <groupId>org.antlr</groupId> + <artifactId>antlr</artifactId> + <version>3.3</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-decisiontables</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>org.antlr</groupId> + <artifactId>antlr-runtime</artifactId> + <version>3.3</version> + </dependency> + <dependency> + <groupId>org.antlr</groupId> + <artifactId>stringtemplate</artifactId> + <version>3.2.1</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-jsr94</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>knowledge-internal-api</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>knowledge-api</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>org.mvel</groupId> + <artifactId>mvel2</artifactId> + <version>2.1.3.Final</version> + </dependency> + <!--dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.6.4</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.6.4</version> + </dependency--> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-verifier</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-templates</artifactId> + <version>${drools.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jdt.core.compiler</groupId> + <artifactId>ecj</artifactId> + <version>3.5.1</version> + </dependency> + <dependency> + <groupId>xmlpull</groupId> + <artifactId>xmlpull</artifactId> + <version>1.1.3.1</version> + </dependency> + <dependency> + <groupId>xpp3</groupId> + <artifactId>xpp3_min</artifactId> + <version>1.1.4c</version> + </dependency> + <dependency> + <groupId>com.lowagie</groupId> + <artifactId>itext</artifactId> + <version>2.1.2</version> + </dependency> + <dependency> + <groupId>jsr94</groupId> + <artifactId>jsr94</artifactId> + <version>1.1</version> + </dependency> + <dependency> + <groupId>org.apache.stratos</groupId> + <artifactId>org.apache.stratos.messaging</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> <dependency> <groupId>org.apache.stratos</groupId> <artifactId>org.apache.stratos.common</artifactId> @@ -170,7 +171,7 @@ <version>${project.version}</version> <scope>provided</scope> </dependency> - <dependency> + <dependency> <groupId>org.apache.stratos</groupId> <artifactId>org.apache.stratos.manager.cleanup.notification.stub</artifactId> <version>${project.version}</version> @@ -182,37 +183,44 @@ <scope>provided</scope> <version>4.2.0</version> </dependency> + <dependency> + <groupId>org.apache.stratos</groupId> + <artifactId>org.apache.stratos.metadata.client</artifactId> + <version>${project.version}</version> + </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> + </dependencies> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> - <Bundle-Name>${project.artifactId}</Bundle-Name> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Bundle-Name>${project.artifactId}</Bundle-Name> <Private-Package>org.apache.stratos.autoscaler.internal.*</Private-Package> - <Export-Package>!org.apache.stratos.autoscaler.internal.*,org.apache.stratos.autoscaler.*</Export-Package> - <Import-Package> - org.osgi.framework.*;resolution:=optional, - *;resolution:=optional + <Export-Package>!org.apache.stratos.autoscaler.internal.*,org.apache.stratos.autoscaler.* + </Export-Package> + <Import-Package> + org.osgi.framework.*;resolution:=optional, + *;resolution:=optional </Import-Package> - <Bundle-Activator>org.apache.stratos.autoscaler.internal.ASBundleActivater</Bundle-Activator> - <DynamicImport-Package>*</DynamicImport-Package> - <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> - <Embed-Directory>lib</Embed-Directory> - </instructions> - </configuration> - </plugin> + <Bundle-Activator>org.apache.stratos.autoscaler.internal.ASBundleActivater</Bundle-Activator> + <DynamicImport-Package>*</DynamicImport-Package> + <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> + <Embed-Directory>lib</Embed-Directory> + </instructions> + </configuration> + </plugin> <plugin> <groupId>org.apache.axis2</groupId> <artifactId>axis2-java2wsdl-maven-plugin</artifactId> @@ -229,17 +237,17 @@ </execution> </executions> </plugin> - </plugins> + </plugins> <resources> - <resource> - <directory>src/main/rules</directory> - </resource> - <resource> - <directory>src/main/resources</directory> - </resource> - </resources> - </build> - <properties> + <resource> + <directory>src/main/rules</directory> + </resource> + <resource> + <directory>src/main/resources</directory> + </resource> + </resources> + </build> + <properties> <drools.version>5.5.0.Final</drools.version> </properties> </project> http://git-wip-us.apache.org/repos/asf/stratos/blob/bcf2e2b6/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java index 4476b1a..62f71f1 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java @@ -41,14 +41,20 @@ import org.apache.stratos.autoscaler.policy.PolicyManager; import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; import org.apache.stratos.autoscaler.registry.RegistryManager; import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; -import org.apache.stratos.common.xsd.Properties; import org.apache.stratos.common.kubernetes.KubernetesGroup; import org.apache.stratos.common.kubernetes.KubernetesHost; import org.apache.stratos.common.kubernetes.KubernetesMaster; +import org.apache.stratos.common.xsd.Properties; import org.apache.stratos.messaging.domain.applications.Application; +import org.apache.stratos.metadata.client.defaults.DefaultMetaDataServiceClient; +import org.apache.stratos.metadata.client.defaults.MetaDataServiceClient; +import org.apache.stratos.metadata.client.exception.MetaDataServiceClientException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Map; +import java.util.Properties; /** * Auto Scaler Service API is responsible getting Partitions and Policies. @@ -288,6 +294,7 @@ public class AutoScalerServiceImpl implements AutoScalerServiceInterface { ApplicationParser applicationParser = new DefaultApplicationParser(); Application application = applicationParser.parse(applicationContext); + publishMetadata(applicationParser, application.getUniqueIdentifier()); ApplicationBuilder.handleApplicationCreated(application, applicationParser.getApplicationClusterContexts()); } @@ -454,4 +461,24 @@ public class AutoScalerServiceImpl implements AutoScalerServiceInterface { } } + + private void publishMetadata(ApplicationParser applicationParser, String appId) { + MetaDataServiceClient metaDataServiceClien = null; + try { + metaDataServiceClien = new DefaultMetaDataServiceClient(); + for (Map.Entry<String, Properties> entry : applicationParser.getAliasToProperties().entrySet()) { + String alias = entry.getKey(); + Properties properties = entry.getValue(); + Enumeration e = properties.propertyNames(); + + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + String value = properties.getProperty(key); + metaDataServiceClien.addPropertyToCluster(appId, alias, key, value); + } + } + } catch (MetaDataServiceClientException e) { + log.error("Could not publish to metadata service ", e); + } + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/bcf2e2b6/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java index f1f59e5..08b515e 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java @@ -24,6 +24,8 @@ import org.apache.stratos.autoscaler.applications.pojo.ApplicationClusterContext import org.apache.stratos.autoscaler.exception.ApplicationDefinitionException; import org.apache.stratos.messaging.domain.applications.Application; +import java.util.Map; +import java.util.Properties; import java.util.Set; /** @@ -50,4 +52,6 @@ public interface ApplicationParser { * @throws ApplicationDefinitionException if any error occurs */ public Set<ApplicationClusterContext> getApplicationClusterContexts() throws ApplicationDefinitionException; + + public Map<String, Properties> getAliasToProperties(); } http://git-wip-us.apache.org/repos/asf/stratos/blob/bcf2e2b6/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java index ce68f8a..8295e90 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java @@ -19,15 +19,6 @@ package org.apache.stratos.autoscaler.applications.parser; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,11 +26,7 @@ import org.apache.stratos.autoscaler.applications.ApplicationUtils; import org.apache.stratos.autoscaler.applications.ClusterInformation; import org.apache.stratos.autoscaler.applications.MTClusterInformation; import org.apache.stratos.autoscaler.applications.STClusterInformation; -import org.apache.stratos.autoscaler.applications.pojo.ApplicationClusterContext; -import org.apache.stratos.autoscaler.applications.pojo.ApplicationContext; -import org.apache.stratos.autoscaler.applications.pojo.GroupContext; -import org.apache.stratos.autoscaler.applications.pojo.SubscribableContext; -import org.apache.stratos.autoscaler.applications.pojo.SubscribableInfoContext; +import org.apache.stratos.autoscaler.applications.pojo.*; import org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient; import org.apache.stratos.autoscaler.exception.ApplicationDefinitionException; import org.apache.stratos.autoscaler.exception.CartridgeInformationException; @@ -51,6 +38,12 @@ import org.apache.stratos.messaging.domain.applications.ClusterDataHolder; import org.apache.stratos.messaging.domain.applications.DependencyOrder; import org.apache.stratos.messaging.domain.applications.Group; +import java.util.*; +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import org.apache.commons.codec.binary.Base64; + /** * Default implementation of the Application Parser. One Application should be processed by one * instance of the DefaultApplicationParser. @@ -60,10 +53,12 @@ public class DefaultApplicationParser implements ApplicationParser { private static Log log = LogFactory.getLog(DefaultApplicationParser.class); private Set<ApplicationClusterContext> applicationClusterContexts; + private Map<String, Properties> aliasToProperties; public DefaultApplicationParser () { - this.applicationClusterContexts = new HashSet<ApplicationClusterContext>(); + this.setAliasToProperties(new HashMap<String, Properties>()); + } @Override @@ -302,6 +297,31 @@ public class DefaultApplicationParser implements ApplicationParser { } } + String alias; + Properties properties = new Properties(); + for (SubscribableInfoContext value : subscribableInfoCtxts.values()) { + alias = value.getAlias(); + String username = value.getRepoUsername(); + String password = value.getRepoPassword(); + String repoUrl = value.getRepoUrl(); + + if (StringUtils.isNotEmpty(username)) { + properties.setProperty("REPO_USERNAME", username); + } + + if (StringUtils.isNotEmpty(password)) { + String encryptedPassword = encryptPassword(password, application.getKey()); + properties.setProperty("REPO_PASSWORD", encryptedPassword); + } + + if (StringUtils.isNotEmpty(repoUrl)) { + properties.setProperty("REPO_URL", repoUrl); + } + + this.addProperties(alias, properties); + } + + log.info("Application with id " + appCtxt.getApplicationId() + " parsed successfully"); return application; @@ -663,4 +683,33 @@ public class DefaultApplicationParser implements ApplicationParser { throw new ApplicationDefinitionException(errorMsg); } + public Map<String, Properties> getAliasToProperties() { + return aliasToProperties; + } + + public void setAliasToProperties(Map<String, Properties> aliasToProperties) { + this.aliasToProperties = aliasToProperties; + } + public void addProperties(String alias, Properties properties) { + this.getAliasToProperties().put(alias, properties); + } + + public static String encryptPassword(String repoUserPassword, String secKey) { + String encryptPassword = ""; + String secret = secKey; // secret key length must be 16 + SecretKey key; + Cipher cipher; + Base64 coder; + key = new SecretKeySpec(secret.getBytes(), "AES"); + try { + cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE"); + coder = new Base64(); + cipher.init(Cipher.ENCRYPT_MODE, key); + byte[] cipherText = cipher.doFinal(repoUserPassword.getBytes()); + encryptPassword = new String(coder.encode(cipherText)); + } catch (Exception e) { + e.printStackTrace(); + } + return encryptPassword; + } }
