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 2013/12/20 05:09:52 UTC
[3/4] Refactoring cartridge agent product to package new standalone
cartridge agent component
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/RepositoryInformation.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/RepositoryInformation.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/RepositoryInformation.java
deleted file mode 100644
index 20df286..0000000
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/RepositoryInformation.java
+++ /dev/null
@@ -1,65 +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.deployment.synchronizer;
-
-/**
- * @author wso2
- *
- */
-public class RepositoryInformation {
-
- private String repoUrl;
- private String repoUsername;
- private String repoPassword;
- private String repoPath;
- private String tenantId;
-
- public String getRepoUrl() {
- return repoUrl;
- }
- public void setRepoUrl(String repoUrl) {
- this.repoUrl = repoUrl;
- }
- public String getRepoUsername() {
- return repoUsername;
- }
- public void setRepoUsername(String repoUsername) {
- this.repoUsername = repoUsername;
- }
- public String getRepoPassword() {
- return repoPassword;
- }
- public void setRepoPassword(String repoPassword) {
- this.repoPassword = repoPassword;
- }
- public String getRepoPath() {
- return repoPath;
- }
- public void setRepoPath(String repoPath) {
- this.repoPath = repoPath;
- }
- public String getTenantId() {
- return tenantId;
- }
- public void setTenantId(String tenantId) {
- this.tenantId = tenantId;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
deleted file mode 100644
index 7586b41..0000000
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
+++ /dev/null
@@ -1,699 +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.deployment.synchronizer.git.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.deployment.synchronizer.ArtifactRepository;
-import org.apache.stratos.deployment.synchronizer.RepositoryInformation;
-import org.apache.stratos.deployment.synchronizer.git.internal.CustomJschConfigSessionFactory;
-import org.apache.stratos.deployment.synchronizer.git.internal.GitDeploymentSynchronizerConstants;
-import org.apache.stratos.deployment.synchronizer.git.internal.RepositoryContext;
-import org.apache.stratos.deployment.synchronizer.git.util.Utilities;
-import org.eclipse.jgit.api.AddCommand;
-import org.eclipse.jgit.api.CloneCommand;
-import org.eclipse.jgit.api.CommitCommand;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.PullCommand;
-import org.eclipse.jgit.api.PushCommand;
-import org.eclipse.jgit.api.RmCommand;
-import org.eclipse.jgit.api.Status;
-import org.eclipse.jgit.api.StatusCommand;
-import org.eclipse.jgit.api.errors.CheckoutConflictException;
-import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.InvalidConfigurationException;
-import org.eclipse.jgit.api.errors.JGitInternalException;
-import org.eclipse.jgit.api.errors.TransportException;
-import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.StoredConfig;
-import org.eclipse.jgit.storage.file.FileRepository;
-import org.eclipse.jgit.transport.SshSessionFactory;
-import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
-
-/**
- * Git based artifact repository.
- *
- *
- */
-public class GitBasedArtifactRepository /*implements ArtifactRepository*/ {
-
- private static final Log log = LogFactory.getLog(GitBasedArtifactRepository.class);
-
- //Map to keep track of git context per tenant (remote urls, jgit git objects, etc.)
- private static ConcurrentHashMap<Integer, RepositoryContext>
- tenantToRepoContextMap = new ConcurrentHashMap<Integer, RepositoryContext>();
-
- private GitBasedArtifactRepository () {
-
- }
-
- /**
- * initializes and populates the git context with relevant data
- *
- * @param tenantId id of the tenant
- *
- * @throws DeploymentSynchronizerException
- */
- private static void initGitContext (RepositoryInformation repositoryInformation) {
-
- /* if (tenantId == GitDeploymentSynchronizerConstants.SUPER_TENANT_ID)
- return;*/
-
- log.info("In init git context............");
-
- int tenantId = Integer.parseInt(repositoryInformation.getTenantId());
- String gitLocalRepoPath = repositoryInformation.getRepoPath();
- RepositoryContext gitRepoCtx = new RepositoryContext();
- String gitRemoteRepoUrl = repositoryInformation.getRepoUrl();
-
- log.info("local path " + gitLocalRepoPath);
- log.info("remote url " + gitRemoteRepoUrl);
- log.info("tenant " + tenantId);
-
- gitRepoCtx.setTenantId(tenantId);
- gitRepoCtx.setGitLocalRepoPath(gitLocalRepoPath);
- gitRepoCtx.setGitRemoteRepoUrl(gitRemoteRepoUrl);
-
- gitRepoCtx.setRepoUsername(repositoryInformation.getRepoUsername());
- gitRepoCtx.setRepoPassword(repositoryInformation.getRepoPassword());
-
- try {
- if(isKeyBasedAuthentication(gitRemoteRepoUrl, tenantId)) {
- gitRepoCtx.setKeyBasedAuthentication(true);
- initSSHAuthentication();
- }
- else
- gitRepoCtx.setKeyBasedAuthentication(false);
- } catch (Exception e1) {
- log.error("Exception occurred.. " + e1.getMessage(), e1);
- }
-
- FileRepository localRepo = null;
- try {
- localRepo = new FileRepository(new File(gitLocalRepoPath + "/.git"));
-
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- gitRepoCtx.setLocalRepo(localRepo);
- gitRepoCtx.setGit(new Git(localRepo));
- gitRepoCtx.setCloneExists(false);
-
- cacheGitRepoContext(tenantId, gitRepoCtx);
- }
-
- /**
- * Checks if key based authentication (SSH) is required
- *
- * @param url git repository url for the tenant
- * @param tenantId id of the tenant
- *
- * @return true if SSH authentication is required, else false
- *
- * @throws DeploymentSynchronizerException
- */
- private static boolean isKeyBasedAuthentication(String url, int tenantId) throws Exception {
-
- if (url.startsWith(GitDeploymentSynchronizerConstants.GIT_HTTP_REPO_URL_PREFIX) ||
- url.startsWith(GitDeploymentSynchronizerConstants.GIT_HTTPS_REPO_URL_PREFIX)) {//http or https url
- // authentication with username and password, not key based
- return false;
- }
-
- else if (url.startsWith(GitDeploymentSynchronizerConstants.GITHUB_READ_ONLY_REPO_URL_PREFIX)) { //github read-only repo url
- // no authentication required
- return false;
- }
-
- else if (url.startsWith(GitDeploymentSynchronizerConstants.GIT_REPO_SSH_URL_PREFIX) ||
- url.contains(GitDeploymentSynchronizerConstants.GIT_REPO_SSH_URL_SUBSTRING)) { //other repo, needs ssh authentication
- // key based authentication
- return true;
- }
-
- else {
- log.error("Invalid git URL provided for tenant " + tenantId);
- throw new Exception("Invalid git URL provided for tenant " + tenantId);
- }
- }
-
- /**
- * Initializes SSH authentication
- */
- private static void initSSHAuthentication () {
-
- SshSessionFactory.setInstance(new CustomJschConfigSessionFactory());
- }
-
- /**
- * Caches RepositoryContext against tenant repository path
- *
- * @param tenantId tenant repository path
- * @param gitRepoCtx RepositoryContext instance for tenant
- */
- private static void cacheGitRepoContext(int tenantId, RepositoryContext gitRepoCtx) {
-
- log.info("caching repo context....");
- tenantToRepoContextMap.put(tenantId, gitRepoCtx);
- }
-
- /**
- * Retrieve cached RepositoryContext relevant to the tenant's local repo path
- *
- * @param tenantLocalRepoPath tenant's local repository path
- *
- * @return corresponding RepositoryContext instance for the
- * tenant's local repo if available, else null
- */
- private static RepositoryContext retrieveCachedGitContext (int tenantId) {
-
- return tenantToRepoContextMap.get(tenantId);
- }
-
- /**
- * Commits any changes in the local repository to the relevant remote repository
- *
- * @return
- *
- */
- public static boolean commit() {
-
- // foreach tenant's local path check for commit
- // TODO implement later, this is applicable for management node.
- //log.info(" In commit.... map count : " + tenantToRepoContextMap.size());
-
- for (Entry<Integer, RepositoryContext> tenantMap : tenantToRepoContextMap
- .entrySet()) {
-
- int tenantId = tenantMap.getKey();
- //log.info("map count has values..tenant Id : " + tenantId);
-
- RepositoryContext gitRepoCtx = retrieveCachedGitContext(tenantId);
- if (gitRepoCtx == null) {
-
- log.info("No git repository context information found for tenant "
- + tenantId);
-
- return false;
- }
-
- Git git = gitRepoCtx.getGit();
- StatusCommand statusCmd = git.status();
- Status status = null;
- try {
- status = statusCmd.call();
-
- } catch (GitAPIException e) {
- log.error(
- "Git status operation for tenant "
- + gitRepoCtx.getTenantId() + " failed, ", e);
- return false;
- }
- //log.info("status : " + status.toString());
- if (status.isClean()) {// no changes, nothing to commit
-
- log.info("No changes detected in the local repository for tenant "
- + tenantId);
- return false;
- }
-
- addArtifacts(gitRepoCtx, getNewArtifacts(status));
- addArtifacts(gitRepoCtx, getModifiedArtifacts(status));
- removeArtifacts(gitRepoCtx, getRemovedArtifacts(status));
- commitToLocalRepo(gitRepoCtx);
- pushToRemoteRepo(gitRepoCtx);
-
- return false;
-
- }
- return false;
- }
-
- /**
- * Returns the newly added artifact set relevant to the current status of the repository
- *
- * @param status git status
- *
- * @return artifact names set
- */
- private static Set<String> getNewArtifacts (Status status) {
-
- return status.getUntracked();
- }
-
- /**
- * Returns the removed (undeployed) artifact set relevant to the current status of the repository
- *
- * @param status git status
- *
- * @return artifact names set
- */
- private static Set<String> getRemovedArtifacts (Status status) {
-
- return status.getMissing();
- }
-
- /**
- * Return the modified artifacts set relevant to the current status of the repository
- *
- * @param status git status
- *
- * @return artifact names set
- */
- private static Set<String> getModifiedArtifacts (Status status) {
-
- return status.getModified();
- }
-
- /**
- * Adds the artifacts to the local staging area
- *
- * @param gitRepoCtx RepositoryContext instance
- * @param artifacts set of artifacts
- */
- private static void addArtifacts (RepositoryContext gitRepoCtx, Set<String> artifacts) {
-
- if(artifacts.isEmpty())
- return;
-
- AddCommand addCmd = gitRepoCtx.getGit().add();
- Iterator<String> it = artifacts.iterator();
- while(it.hasNext())
- addCmd.addFilepattern(it.next());
-
- try {
- addCmd.call();
-
- } catch (GitAPIException e) {
- log.error("Adding artifact to the local repository at " + gitRepoCtx.getGitLocalRepoPath() + "failed", e);
- e.printStackTrace();
- }
- }
-
- /**
- * Removes the set of artifacts from local repo
- *
- * @param gitRepoCtx RepositoryContext instance
- * @param artifacts Set of artifact names to remove
- */
- private static void removeArtifacts (RepositoryContext gitRepoCtx, Set<String> artifacts) {
-
- if(artifacts.isEmpty())
- return;
-
- RmCommand rmCmd = gitRepoCtx.getGit().rm();
- Iterator<String> it = artifacts.iterator();
- while (it.hasNext()) {
- rmCmd.addFilepattern(it.next());
- }
-
- try {
- rmCmd.call();
-
- } catch (GitAPIException e) {
- log.error("Removing artifact from the local repository at " + gitRepoCtx.getGitLocalRepoPath() + "failed", e);
- e.printStackTrace();
- }
- }
-
- /**
- * Commits changes for a tenant to relevant the local repository
- *
- * @param gitRepoCtx RepositoryContext instance for the tenant
- */
- private static void commitToLocalRepo (RepositoryContext gitRepoCtx) {
-
- CommitCommand commitCmd = gitRepoCtx.getGit().commit();
- commitCmd.setMessage("tenant " + gitRepoCtx.getTenantId() + "'s artifacts committed to local repo at " +
- gitRepoCtx.getGitLocalRepoPath());
-
- try {
- commitCmd.call();
-
- } catch (GitAPIException e) {
- log.error("Committing artifacts to local repository failed for tenant " + gitRepoCtx.getTenantId(), e);
- e.printStackTrace();
- }
- }
-
- /**
- * Pushes the artifacts of the tenant to relevant remote repository
- *
- * @param gitRepoCtx RepositoryContext instance for the tenant
- */
- private static void pushToRemoteRepo(RepositoryContext gitRepoCtx) {
-
- PushCommand pushCmd = gitRepoCtx.getGit().push();
- if(!gitRepoCtx.getKeyBasedAuthentication()) {
- UsernamePasswordCredentialsProvider credentialsProvider = createCredentialsProvider(gitRepoCtx);
- if (credentialsProvider != null)
- pushCmd.setCredentialsProvider(credentialsProvider);
- }
-
- try {
- pushCmd.call();
-
- } catch (GitAPIException e) {
- log.error("Pushing artifacts to remote repository failed for tenant " + gitRepoCtx.getTenantId(), e);
- e.printStackTrace();
- }
- }
-
- public static boolean checkout(RepositoryInformation repositoryInformation) {
-
- log.info("In checkout............");
-
- int tenantId = Integer.parseInt(repositoryInformation.getTenantId());
-
- // if context for tenant is not initialized
- if(tenantToRepoContextMap.get(tenantId) == null)
- initGitContext(repositoryInformation);
-
-
- RepositoryContext gitRepoCtx = retrieveCachedGitContext(tenantId);
- if(gitRepoCtx == null) { //to handle super tenant scenario
- // if(log.isDebugEnabled())
- log.info("No git repository context information found for deployment synchronizer ");
-
- return true;
- }
-
- /*if(gitRepoCtx.getTenantId() == GitDeploymentSynchronizerConstants.SUPER_TENANT_ID)
- return true; */
- if(!gitRepoCtx.cloneExists())
- cloneRepository(gitRepoCtx);
-
- return pullArtifacts(gitRepoCtx);
- }
-
-
-
- public static boolean cloneExists(RepositoryInformation repositoryInformation) {
-
- int tenantId = Integer.parseInt(repositoryInformation.getTenantId());
-
- // if context for tenant is not initialized
- if(tenantToRepoContextMap.get(tenantId) == null)
- initGitContext(repositoryInformation);
-
-
- RepositoryContext gitRepoCtx = retrieveCachedGitContext(tenantId);
- if(gitRepoCtx == null) {
- return false;
- }
-
- /*if(gitRepoCtx.getTenantId() == GitDeploymentSynchronizerConstants.SUPER_TENANT_ID)
- return true; */
- return gitRepoCtx.cloneExists();
- }
-
- /**
- * Pulling if any updates are available in the remote git repository. If basic authentication is required,
- * will call 'RepositoryInformationService' for credentials.
- *
- * @param gitRepoCtx RepositoryContext instance for tenant
- *
- * @return true if success, else false
- */
- private static boolean pullArtifacts (RepositoryContext gitRepoCtx) {
-
- log.info("Pullingg.....");
- PullCommand pullCmd = gitRepoCtx.getGit().pull();
-
- if(!gitRepoCtx.getKeyBasedAuthentication()) {
- UsernamePasswordCredentialsProvider credentialsProvider = createCredentialsProvider(gitRepoCtx);
- if (credentialsProvider != null)
- pullCmd.setCredentialsProvider(credentialsProvider);
- }
-
- try {
- pullCmd.call();
-
- } catch (InvalidConfigurationException e) {
- log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", " + e.getMessage());
- //handleInvalidConfigurationError(gitRepoCtx);
- //return false;
- Utilities.deleteFolderStructure(new File(gitRepoCtx.getGitLocalRepoPath()));
- cloneRepository(gitRepoCtx);
- return true;
-
- } catch (JGitInternalException e) {
- log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", " + e.getMessage());
- return false;
-
- } catch (TransportException e) {
- log.error("Accessing remote git repository " + gitRepoCtx.getGitRemoteRepoUrl() + " failed for tenant " + gitRepoCtx.getTenantId(), e);
- e.printStackTrace();
- return false;
-
- } catch (CheckoutConflictException e) { //TODO: handle conflict efficiently. Currently the whole directory is deleted and re-cloned
- log.warn("Git pull for the path " + e.getConflictingPaths().toString() + " failed due to conflicts");
- Utilities.deleteFolderStructure(new File(gitRepoCtx.getGitLocalRepoPath()));
- cloneRepository(gitRepoCtx);
- return true;
-
- } catch (GitAPIException e) {
- log.error("Git pull operation for tenant " + gitRepoCtx.getTenantId() + " failed", e);
- e.printStackTrace();
- return false;
- }
-
- return true;
- }
-
- /**
- * Handles the Invalid configuration issues
- *
- * @param gitRepoCtx RepositoryContext instance of the tenant
- */
- private void handleInvalidConfigurationError (RepositoryContext gitRepoCtx) {
-
- StoredConfig storedConfig = gitRepoCtx.getLocalRepo().getConfig();
- boolean modifiedConfig = false;
- if(storedConfig != null) {
-
- if(storedConfig.getString("branch", "master", "remote") == null ||
- storedConfig.getString("branch", "master", "remote").isEmpty()) {
-
- storedConfig.setString("branch", "master", "remote", "origin");
- modifiedConfig = true;
- }
-
- if(storedConfig.getString("branch", "master", "merge") == null ||
- storedConfig.getString("branch", "master", "merge").isEmpty()) {
-
- storedConfig.setString("branch", "master", "merge", "refs/heads/master");
- modifiedConfig = true;
- }
-
- if(modifiedConfig) {
- try {
- storedConfig.save();
- // storedConfig.load();
-
- } catch (IOException e) {
- log.error("Error saving git configuration file in local repo at " + gitRepoCtx.getGitLocalRepoPath(), e);
- e.printStackTrace();
-
- } /*catch (ConfigInvalidException e) {
- log.error("Invalid configurations in local repo at " + gitRepoCtx.getGitLocalRepoPath(), e);
- e.printStackTrace();
- } */
- }
- }
- }
-
- /**
- * Clones the remote repository to the local one. If basic authentication is required,
- * will call 'RepositoryInformationService' for credentials.
- *
- * @param gitRepoCtx RepositoryContext for the tenant
- */
- private static void cloneRepository (RepositoryContext gitRepoCtx) { //should happen only at the beginning
-
- File gitRepoDir = new File(gitRepoCtx.getGitLocalRepoPath());
- if (gitRepoDir.exists()) {
- if(isValidGitRepo(gitRepoCtx)) { //check if a this is a valid git repo
- log.info("Existing git repository detected for tenant " + gitRepoCtx.getTenantId() + ", no clone required");
- gitRepoCtx.setCloneExists(true);
- return;
- }
- else {
- if(log.isDebugEnabled())
- log.debug("Repository for tenant " + gitRepoCtx.getTenantId() + " is not a valid git repo");
- Utilities.deleteFolderStructure(gitRepoDir); //if not a valid git repo but non-empty, delete it (else the clone will not work)
- }
- }
-
- CloneCommand cloneCmd = gitRepoCtx.getGit().cloneRepository().
- setURI(gitRepoCtx.getGitRemoteRepoUrl()).
- setDirectory(gitRepoDir);
-
- if(!gitRepoCtx.getKeyBasedAuthentication()) {
- UsernamePasswordCredentialsProvider credentialsProvider = createCredentialsProvider(gitRepoCtx);
- if (credentialsProvider != null)
- cloneCmd.setCredentialsProvider(credentialsProvider);
- }
-
- try {
- cloneCmd.call();
- log.info("Git clone operation for tenant " + gitRepoCtx.getTenantId() + " successful");
- gitRepoCtx.setCloneExists(true);
-
- } catch (TransportException e) {
- log.error("Accessing remote git repository failed for tenant " + gitRepoCtx.getTenantId(), e);
- e.printStackTrace();
-
- } catch (GitAPIException e) {
- log.error("Git clone operation for tenant " + gitRepoCtx.getTenantId() + " failed", e);
- e.printStackTrace();
- }
- }
-
- /**
- * Queries the RepositoryInformationService to obtain credentials for the tenant id + cartridge type
- * and creates a UsernamePasswordCredentialsProvider from a valid username and a password
- *
- * @param gitRepoCtx RepositoryContext instance
- *
- * @return UsernamePasswordCredentialsProvider instance or null if service invocation failed or
- * username/password is not valid
- */
- private static UsernamePasswordCredentialsProvider createCredentialsProvider (RepositoryContext gitRepoCtx) {
-
- //RepositoryCredentials repoCredentials = null;
- // TODO - set repo creds using the received message
- //repoCredentials = new RepositoryCredentials();
-
- /*try {
- repoCredentials = gitRepoCtx.getRepoInfoServiceClient().
- getJsonRepositoryInformation(gitRepoCtx.getTenantId(), cartridgeShortName);
-
- } catch (Exception e) {
- log.error("Git json repository information query failed", e);
- return null;
- }*/
-
- /*if (repoCredentials != null) {
- String userName = repoCredentials.getUserName();
- String password = repoCredentials.getPassword();
-
- log.info("Recieved repo url [" + repoCredentials.getUrl() + "] for tenant " + gitRepoCtx.getTenantId() +
- ", username " + userName);
-
- if (userName!= null && password != null) {
- return new UsernamePasswordCredentialsProvider(userName, password);
- }
- }*/
-
- return new UsernamePasswordCredentialsProvider(gitRepoCtx.getRepoUsername(), gitRepoCtx.getRepoPassword());
- }
-
- /**
- * Checks if an existing local repository is a valid git repository
- *
- * @param gitRepoCtx RepositoryContext instance
- *
- * @return true if a valid git repo, else false
- */
- private static boolean isValidGitRepo (RepositoryContext gitRepoCtx) {
-
- for (Ref ref : gitRepoCtx.getLocalRepo().getAllRefs().values()) { //check if has been previously cloned successfully, not empty
- if (ref.getObjectId() == null)
- continue;
- return true;
- }
-
- return false;
- }
-
- /**
- * Calls a utility method to extract the username from a json string
- *
- * @param repoInfoJsonString json format string
- *
- * @return username if exists, else an empty String
- */
- private String getUserName (String repoInfoJsonString) {
- return Utilities.getMatch(repoInfoJsonString,
- GitDeploymentSynchronizerConstants.USERNAME_REGEX, 1);
- }
-
- /**
- * Calls a utility method to extract the password from a json string
- *
- * @param repoInfoJsonString json format string
- *
- * @return password if exists, else an empty String
- */
- private String getPassword (String repoInfoJsonString) {
- return Utilities.getMatch(repoInfoJsonString,
- GitDeploymentSynchronizerConstants.PASSWORD_REGEX, 1);
- }
-
- /* public void initAutoCheckout(boolean b) throws Exception {
-
- }*/
-
- public void cleanupAutoCheckout() {
-
- }
-
- public String getRepositoryType() {
-
- return /*DeploymentSynchronizerConstants.REPOSITORY_TYPE_GIT;*/null;
- }
-
- /* public List<RepositoryConfigParameter> getParameters() {
-
- return null;
- }*/
-
- //public boolean update(String rootPath, String filePath, int depth) throws DeploymentSynchronizerException {
-
- // TODO - implemetn later
-
- /*RepositoryContext gitRepoCtx = retrieveCachedGitContext(filePath);
- if(gitRepoCtx == null) {
- if(log.isDebugEnabled())
- log.debug("No git repository context information found for deployment synchonizer at " + filePath);
-
- return false;
- }
- if(gitRepoCtx.getTenantId() == GitDeploymentSynchronizerConstants.SUPER_TENANT_ID)
- return true; //Super Tenant is inactive
- if(gitRepoCtx.cloneExists())
- return pullArtifacts(gitRepoCtx);*/
-
- /* return false;
- }*/
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/CustomJschConfigSessionFactory.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/CustomJschConfigSessionFactory.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/CustomJschConfigSessionFactory.java
deleted file mode 100644
index 7f67d2c..0000000
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/CustomJschConfigSessionFactory.java
+++ /dev/null
@@ -1,64 +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.deployment.synchronizer.git.internal;
-
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import org.eclipse.jgit.transport.JschConfigSessionFactory;
-import org.eclipse.jgit.transport.OpenSshConfig;
-import org.eclipse.jgit.util.FS;
-import org.wso2.carbon.base.ServerConfiguration;
-
-/**
- * overrides the default org.eclipse.jgit.transport.JschConfigSessionFactory
- */
-public class CustomJschConfigSessionFactory extends JschConfigSessionFactory {
-
- @Override
- protected void configure(OpenSshConfig.Host host, Session session) {
- java.util.Properties config = new java.util.Properties();
- config.put("StrictHostKeyChecking", "no");
- session.setConfig(config);
- }
-
- @Override
- protected JSch createDefaultJSch(FS fs) throws JSchException {
-
- JSch def = super.createDefaultJSch(fs);
- String keyName = ServerConfiguration.getInstance().
- getFirstProperty(GitDeploymentSynchronizerConstants.SSH_PRIVATE_KEY_NAME);
- String keyPath = ServerConfiguration.getInstance().
- getFirstProperty(GitDeploymentSynchronizerConstants.SSH_PRIVATE_KEY_PATH);
-
- if(keyName == null || keyName.isEmpty())
- keyName = GitDeploymentSynchronizerConstants.SSH_KEY;
-
- if(keyPath == null || keyPath.isEmpty())
- keyPath = System.getProperty("user.home") + "/" +GitDeploymentSynchronizerConstants.SSH_KEY_DIRECTORY;
-
- if(keyPath.endsWith("/"))
- def.addIdentity(keyPath + keyName);
- else
- def.addIdentity(keyPath + "/" + keyName);
-
- return def;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/GitDeploymentSynchronizerConstants.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/GitDeploymentSynchronizerConstants.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/GitDeploymentSynchronizerConstants.java
deleted file mode 100644
index 5a2450d..0000000
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/GitDeploymentSynchronizerConstants.java
+++ /dev/null
@@ -1,61 +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.deployment.synchronizer.git.internal;
-
-
-/**
- * Git based DeploymentSynchronizer constansts
- */
-public class GitDeploymentSynchronizerConstants {
-
- //Git repo url related constansts
- //public static final String GITHUB_HTTP_REPO_URL_PREFIX = "http://github.com";
- public static final String GIT_HTTP_REPO_URL_PREFIX = "http://";
- //public static final String GITHUB_HTTPS_REPO_URL_PREFIX = "https://github.com";
- public static final String GIT_HTTPS_REPO_URL_PREFIX = "https://";
- public static final String GITHUB_READ_ONLY_REPO_URL_PREFIX = "git://github.com";
- public static final String GIT_REPO_SSH_URL_PREFIX = "ssh://";
- public static final String GIT_REPO_SSH_URL_SUBSTRING = "@";
-
- //SSH related constants
- public static final String SSH_KEY_DIRECTORY = ".ssh";
- public static final String SSH_KEY = "wso2";
-
- //super tenant Id
- public static final int SUPER_TENANT_ID = -1234;
-
- //ServerKey property name from carbon.xml, for the cartridge short name --> not used. CARTRIDGE_ALIAS is used instead.
- //public static final String SERVER_KEY = "ServerKey";
-
- //EPR for the repository Information Service
- public static final String REPO_INFO_SERVICE_EPR = "RepoInfoServiceEpr";
-
- //CartridgeAlias property name from carbon.xml
- public static final String CARTRIDGE_ALIAS = "CartridgeAlias";
-
- //key name and path for ssh based authentication
- public static final String SSH_PRIVATE_KEY_NAME = /*DEPLOYMENT_SYNCHRONIZER + */".SshPrivateKeyName";
- public static final String SSH_PRIVATE_KEY_PATH = /*DEPLOYMENT_SYNCHRONIZER +*/ ".SshPrivateKeyPath";
-
- //regular expressions for extracting username and password form json string
- public static final String USERNAME_REGEX = "username:(.*?),";
- public static final String PASSWORD_REGEX = "password:(.*?)}";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/RepositoryContext.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/RepositoryContext.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/RepositoryContext.java
deleted file mode 100644
index 5f11077..0000000
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/internal/RepositoryContext.java
+++ /dev/null
@@ -1,131 +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.deployment.synchronizer.git.internal;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.lib.Repository;
-
-import java.io.File;
-
-/**
- * Git Repository Context class. Keeps track of git configurations per tenant.
- */
-public class RepositoryContext {
-
- private static final Log log = LogFactory.getLog(RepositoryContext.class);
-
- private String gitRemoteRepoUrl;
- private String gitLocalRepoPath;
- private Repository localRepo;
- private Git git;
- private boolean cloneExists;
- private int tenantId;
- private File gitRepoDir;
- private boolean keyBasedAuthentication;
- private String repoUsername;
- private String repoPassword;
-
- public RepositoryContext () {
-
- }
-
- public String getGitRemoteRepoUrl() {
- return gitRemoteRepoUrl;
- }
-
- public void setGitRemoteRepoUrl(String gitRemoteRepoUrl) {
- this.gitRemoteRepoUrl = gitRemoteRepoUrl;
- }
-
- public String getGitLocalRepoPath() {
- return gitLocalRepoPath;
- }
-
- public void setGitLocalRepoPath(String gitLocalRepoPath) {
- this.gitLocalRepoPath = gitLocalRepoPath;
- }
-
- public Repository getLocalRepo() {
- return localRepo;
- }
-
- public void setLocalRepo(Repository localRepo) {
- this.localRepo = localRepo;
- }
-
- public Git getGit() {
- return git;
- }
-
- public void setGit(Git git) {
- this.git = git;
- }
-
- public boolean cloneExists() {
- return cloneExists;
- }
-
- public void setCloneExists(boolean cloneExists) {
- this.cloneExists = cloneExists;
- }
-
- public int getTenantId() {
- return tenantId;
- }
-
- public void setTenantId(int tenantId) {
- this.tenantId = tenantId;
- }
-
- public File getGitRepoDir() {
- return gitRepoDir;
- }
-
- public void setGitRepoDir(File gitRepoDir) {
- this.gitRepoDir = gitRepoDir;
- }
-
- public boolean getKeyBasedAuthentication() {
- return keyBasedAuthentication;
- }
-
- public void setKeyBasedAuthentication(boolean keyBasedAuthentication) {
- this.keyBasedAuthentication = keyBasedAuthentication;
- }
-
- public String getRepoUsername() {
- return repoUsername;
- }
-
- public void setRepoUsername(String repoUsername) {
- this.repoUsername = repoUsername;
- }
-
- public String getRepoPassword() {
- return repoPassword;
- }
-
- public void setRepoPassword(String repoPassword) {
- this.repoPassword = repoPassword;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/GitDeploymentSyncronizerConfiguration.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/GitDeploymentSyncronizerConfiguration.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/GitDeploymentSyncronizerConfiguration.java
deleted file mode 100644
index d05642e..0000000
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/GitDeploymentSyncronizerConfiguration.java
+++ /dev/null
@@ -1,29 +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.deployment.synchronizer.git.util;
-
-/**
- * Configuration class
- */
-public class GitDeploymentSyncronizerConfiguration {
-
- //public static String CARTRIDGE_SHORT_NAME;
- //can take the server key from the name itself as default
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/Utilities.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/Utilities.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/Utilities.java
deleted file mode 100644
index d09a76d..0000000
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/util/Utilities.java
+++ /dev/null
@@ -1,73 +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.deployment.synchronizer.git.util;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * String Utility methods
- */
-public class Utilities {
-
- private static final Log log = LogFactory.getLog(Utilities.class);
-
- /**
- * Searches for a match in a input String against a regex
- *
- * @param input input String
- * @param regex regex to match
- * @param group grouping,
- *
- * @return result of the match if found, else empty String
- */
- public static String getMatch (String input, String regex, int group) {
-
- String whitespaceRemovedJsonString = input.replaceAll("\\s+","");
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(whitespaceRemovedJsonString);
- if(!matcher.find())
- return "";
- else
- return matcher.group(group).trim();
- }
-
- /**
- * Deletes a folder structure recursively
- *
- * @param existingDir folder to delete
- */
- public static void deleteFolderStructure (File existingDir) {
-
- try {
- FileUtils.deleteDirectory(existingDir);
-
- } catch (IOException e) {
- log.error("Deletion of existing non-git repository structure failed");
- e.printStackTrace();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/pom.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/pom.xml b/products/cartridge-agent/modules/distribution/pom.xml
new file mode 100644
index 0000000..c83b868
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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>cartidge-agent</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>apache-stratos-cartridge-agent</artifactId>
+ <name>Apache Stratos - Cartridge Agent</name>
+
+ <repositories>
+ <repository>
+ <id>wso2-nexus</id>
+ <name>WSO2 internal Repository</name>
+ <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>daily</updatePolicy>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.cartridge.agent</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.stratos.cartridge.agent.Main</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2.1</version>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/bin.xml</descriptor>
+ </descriptors>
+ <archiverConfig>
+ <fileMode>420</fileMode>
+ <directoryMode>493</directoryMode>
+ <defaultDirectoryMode>493</defaultDirectoryMode>
+ </archiverConfig>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/assembly/bin.xml b/products/cartridge-agent/modules/distribution/src/main/assembly/bin.xml
new file mode 100644
index 0000000..4aa54f2
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/src/main/assembly/bin.xml
@@ -0,0 +1,79 @@
+<!--
+ ~ 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.
+ -->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>bin</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <fileSets>
+ <fileSet>
+ <directory>${project.basedir}/src/main/bin</directory>
+ <outputDirectory>/bin</outputDirectory>
+ <fileMode>0755</fileMode>
+ <includes>
+ <include>cartridge-agent.sh</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>${project.basedir}/src/main/conf</directory>
+ <outputDirectory>/conf</outputDirectory>
+ <fileMode>0600</fileMode>
+ <includes>
+ <include>jndi.properties</include>
+ <include>log4j.properties</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>${project.basedir}/src/main/conf/templates</directory>
+ <outputDirectory>/conf/templates</outputDirectory>
+ <fileMode>0600</fileMode>
+ <includes>
+ <include>jndi.properties.template</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>${project.basedir}/src/main/security</directory>
+ <outputDirectory>/security</outputDirectory>
+ <fileMode>0600</fileMode>
+ <includes>
+ <include>client-truststore.jks</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>${project.basedir}</directory>
+ <outputDirectory>/</outputDirectory>
+ <fileMode>0600</fileMode>
+ <includes>
+ <include>README*</include>
+ <include>LICENSE*</include>
+ <include>NOTICE*</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/lib</outputDirectory>
+ <useProjectArtifact>true</useProjectArtifact>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/src/main/bin/cartridge-agent.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/bin/cartridge-agent.sh b/products/cartridge-agent/modules/distribution/src/main/bin/cartridge-agent.sh
new file mode 100644
index 0000000..c03bad3
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/src/main/bin/cartridge-agent.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+# --------------------------------------------------------------
+#
+# 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.
+#
+# --------------------------------------------------------------
+
+echo "Starting cartridge agent..."
+script_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )/`dirname $0`"
+lib_path=${script_path}/../lib/
+class_path=`echo ${lib_path}/*.jar | tr ' ' ':'`
+properties="-Dmb.ip=localhost
+ -Dmb.port=5677
+ -Dthrift.receiver.ip=localhost
+ -Dthrift.receiver.port=7615
+ -Djndi.properties.template.file.path=${script_path}/../conf/templates/jndi.properties.template
+ -Djndi.properties.dir=${script_path}/../conf
+ -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties"
+ -Dparam.file.path=/opt/apache-stratos-cartridge-agent/payload/launch.params
+
+# Uncomment below line to enable remote debugging
+#debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
+
+java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.cartridge.agent.Main
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/src/main/conf/jndi.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/conf/jndi.properties b/products/cartridge-agent/modules/distribution/src/main/conf/jndi.properties
new file mode 100644
index 0000000..c88ec1d
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/src/main/conf/jndi.properties
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+connectionfactoryName=topicConnectionfactory
+connectionfactory.topicConnectionfactory=amqp://admin:admin@carbon/carbon?brokerlist='tcp://localhost:5677'
+java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory
+java.naming.provider.url=repository/conf/jndi.properties
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/src/main/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/conf/log4j.properties b/products/cartridge-agent/modules/distribution/src/main/conf/log4j.properties
new file mode 100644
index 0000000..620d0b9
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/src/main/conf/log4j.properties
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+
+# Set root logger level and appenders
+log4j.rootLogger=INFO, CONSOLE_APPENDER, FILE_APPENDER
+
+# CONSOLE_APPENDER is set to be a ConsoleAppender.
+log4j.appender.CONSOLE_APPENDER=org.apache.log4j.ConsoleAppender
+
+# The standard error log where all the warnings, errors and fatal errors will be logged
+log4j.appender.FILE_APPENDER=org.apache.log4j.FileAppender
+log4j.appender.FILE_APPENDER.File=/var/log/apache-stratos/cartridge-agent-event-publisher.log
+log4j.appender.FILE_APPENDER.layout=org.apache.log4j.PatternLayout
+log4j.appender.FILE_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n
+log4j.appender.FILE_APPENDER.threshold=DEBUG
+
+# CONSOLE_APPENDER uses PatternLayout.
+log4j.appender.CONSOLE_APPENDER.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE_APPENDER.layout.ConversionPattern=[%d{ISO8601}] %5p - [%c{1}] %m%n
+
+log4j.logger.org.apache.stratos.cartridge.agent=INFO
+log4j.logger.org.apache.stratos.messaging=INFO
+log4j.logger.org.wso2.andes.client=ERROR
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/src/main/conf/templates/jndi.properties.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/conf/templates/jndi.properties.template b/products/cartridge-agent/modules/distribution/src/main/conf/templates/jndi.properties.template
new file mode 100644
index 0000000..9ccf044
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/src/main/conf/templates/jndi.properties.template
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+# This is a generated file and will be overwritten at the next load balancer startup.
+# Please use loadbalancer.conf for updating mb-ip, mb-port and templates/jndi.properties.template
+# file for updating other configurations.
+#
+connectionfactoryName=topicConnectionfactory
+connectionfactory.topicConnectionfactory=amqp://admin:admin@carbon/carbon?brokerlist='tcp://$mb_ip:$mb_port'
+java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory
+java.naming.provider.url=repository/conf/jndi.properties
+
+
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/resources/jndi.properties b/products/cartridge-agent/modules/distribution/src/main/resources/jndi.properties
new file mode 100644
index 0000000..c928585
--- /dev/null
+++ b/products/cartridge-agent/modules/distribution/src/main/resources/jndi.properties
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+connectionfactoryName=topicConnectionfactory
+connectionfactory.topicConnectionfactory=amqp://admin:admin@carbon/carbon?brokerlist='tcp://MB-IP-ADDRESS:MB-PORT'
+java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory
+java.naming.provider.url=repository/conf/jndi.properties
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/distribution/src/main/security/client-truststore.jks
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/distribution/src/main/security/client-truststore.jks b/products/cartridge-agent/modules/distribution/src/main/security/client-truststore.jks
new file mode 100644
index 0000000..be441f3
Binary files /dev/null and b/products/cartridge-agent/modules/distribution/src/main/security/client-truststore.jks differ
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/pom.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/pom.xml b/products/cartridge-agent/modules/event-publisher/pom.xml
deleted file mode 100644
index 7f6c3b7..0000000
--- a/products/cartridge-agent/modules/event-publisher/pom.xml
+++ /dev/null
@@ -1,120 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<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>cartidge-agent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>apache-stratos-event-publisher</artifactId>
- <name>Apache Stratos - Event Publisher</name>
-
- <repositories>
- <repository>
- <id>wso2-nexus</id>
- <name>WSO2 internal Repository</name>
- <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
- <releases>
- <enabled>true</enabled>
- <updatePolicy>daily</updatePolicy>
- <checksumPolicy>ignore</checksumPolicy>
- </releases>
- </repository>
- </repositories>
-
- <dependencies>
- <dependency>
- <groupId>org.wso2.andes.wso2</groupId>
- <artifactId>andes-client</artifactId>
- <version>0.13.wso2v8</version>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs.wso2</groupId>
- <artifactId>geronimo-jms_1.1_spec</artifactId>
- <version>1.1.0.wso2v1</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.5</version>
- </dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.2.4</version>
- </dependency>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.messaging</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.0</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.4</version>
- <configuration>
- <archive>
- <manifest>
- <mainClass>org.apache.stratos.cartridge.agent.event.publisher.Main</mainClass>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2.1</version>
- <configuration>
- <descriptors>
- <descriptor>src/main/assembly/bin.xml</descriptor>
- </descriptors>
- <archiverConfig>
- <fileMode>420</fileMode>
- <directoryMode>493</directoryMode>
- <defaultDirectoryMode>493</defaultDirectoryMode>
- </archiverConfig>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>attached</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/assembly/bin.xml b/products/cartridge-agent/modules/event-publisher/src/main/assembly/bin.xml
deleted file mode 100644
index 93f860f..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/assembly/bin.xml
+++ /dev/null
@@ -1,63 +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.
- -->
-
-<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
- <id>bin</id>
- <formats>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}/src/main/bin</directory>
- <outputDirectory>/bin</outputDirectory>
- <fileMode>0755</fileMode>
- <includes>
- <include>event-publisher.sh</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.basedir}/src/main/templates</directory>
- <outputDirectory>/templates</outputDirectory>
- <fileMode>0600</fileMode>
- <includes>
- <include>member-started-event.json.template</include>
- <include>member-activated-event.json.template</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.basedir}</directory>
- <outputDirectory>/</outputDirectory>
- <fileMode>0600</fileMode>
- <includes>
- <include>README*</include>
- <include>LICENSE*</include>
- <include>NOTICE*</include>
- </includes>
- </fileSet>
- </fileSets>
- <dependencySets>
- <dependencySet>
- <outputDirectory>/lib</outputDirectory>
- <useProjectArtifact>true</useProjectArtifact>
- <scope>runtime</scope>
- </dependencySet>
- </dependencySets>
-</assembly>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/bin/event-publisher.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/bin/event-publisher.sh b/products/cartridge-agent/modules/event-publisher/src/main/bin/event-publisher.sh
deleted file mode 100755
index 2a933b7..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/bin/event-publisher.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-# --------------------------------------------------------------
-#
-# 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.
-#
-# --------------------------------------------------------------
-
-echo "Starting event publisher..."
-lib_path=./../lib/
-class_path=${lib_path}commons-io-2.0.jar:${lib_path}andes-client-0.13.wso2v8.jar:${lib_path}apache-stratos-event-publisher-4.0.0-SNAPSHOT.jar:${lib_path}commons-codec-1.8.jar:${lib_path}commons-logging-1.1.1.jar:${lib_path}geronimo-jms_1.1_spec-1.1.0.wso2v1.jar:${lib_path}geronimo-jms_1.1_spec-1.1.jar:${lib_path}gson-2.2.4.jar:${lib_path}log4j-1.2.13.jar:${lib_path}org.apache.log4j-1.2.13.v200706111418.jar:${lib_path}org.apache.stratos.messaging-4.0.0-SNAPSHOT.jar:${lib_path}org.wso2.carbon.logging-4.1.0.jar:${lib_path}slf4j-api-1.7.5.jar:${lib_path}slf4j-log4j12-1.7.5.jar
-
-java -cp $class_path org.apache.stratos.cartridge.agent.event.publisher.Main $*
-echo "Event publisher completed"
-
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java b/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java
deleted file mode 100644
index 8136670..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java
+++ /dev/null
@@ -1,108 +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.cartridge.agent.event.publisher;
-
-import com.google.gson.Gson;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.util.Constants;
-
-import javax.jms.*;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.util.Properties;
-
-/**
- * A generic topic publisher.
- */
-public class EventPublisher {
- private static final Log log = LogFactory.getLog(EventPublisher.class);
-
- private TopicConnection topicConnection;
- private TopicSession topicSession;
- private Topic topic;
- private String mbIpAddress;
- private int mbPort;
- private String topicName;
-
- public EventPublisher(String mbIpAddress, int mbPort, String topicName) {
- this.mbIpAddress = mbIpAddress;
- this.mbPort = mbPort;
- this.topicName = topicName;
- }
-
- private Properties getProperties() throws IOException {
- Properties properties = new Properties();
- properties.load(EventPublisher.class.getClassLoader().getResourceAsStream("jndi.properties"));
-
- // Set message broker ip and port
- String connectionFactoryName = properties.get("connectionfactoryName").toString();
- String key = "connectionfactory." + connectionFactoryName;
- String connectionFactoryStr = (String) properties.get(key);
- connectionFactoryStr = connectionFactoryStr.replace("MB-IP-ADDRESS", mbIpAddress);
- connectionFactoryStr = connectionFactoryStr.replace("MB-PORT", String.valueOf(mbPort));
- properties.setProperty(key, connectionFactoryStr);
-
- return properties;
- }
-
- public void connect() throws NamingException, JMSException, IOException {
- // Prepare JNDI properties
- Properties properties = getProperties();
- InitialContext ctx = new InitialContext(properties);
-
- // Lookup connection factory
- String connectionFactoryName = properties.get("connectionfactoryName").toString();
- TopicConnectionFactory connectionFactory = (TopicConnectionFactory) ctx.lookup(connectionFactoryName);
- topicConnection = connectionFactory.createTopicConnection();
- topicConnection.start();
- topicSession = topicConnection.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-
- // Create topic
- topic = topicSession.createTopic(topicName);
- }
-
- public void publish(Event event) throws NamingException, JMSException, IOException {
- Gson gson = new Gson();
- String json = gson.toJson(event);
- publish(json, event.getClass().getName());
- }
-
- private void publish(String message, String eventClassName) throws NamingException, JMSException, IOException {
- TextMessage textMessage = topicSession.createTextMessage((String) message);
- textMessage.setStringProperty(Constants.EVENT_CLASS_NAME, eventClassName);
- javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);
- topicPublisher.publish(textMessage);
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Message published: [topic] %s [header] %s [body] %s", topicName, eventClassName, message));
- }
- }
-
- public void close() throws JMSException {
- // Clean up resources
- if (topicSession != null)
- topicSession.close();
- if (topicConnection != null)
- topicConnection.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java b/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java
deleted file mode 100644
index dcc0c83..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java
+++ /dev/null
@@ -1,102 +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.cartridge.agent.event.publisher;
-
-import com.google.gson.Gson;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.event.Event;
-
-import javax.jms.JMSException;
-import javax.naming.NamingException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-/**
- * Cartridge agent lifecycle implementation.
- */
-public class EventPublisherClient {
- private static final Log log = LogFactory.getLog(EventPublisherClient.class);
-
- private String mbIpAddress;
- private int mbPort;
- private String eventClassName;
- private String jsonFilePath;
-
- public EventPublisherClient(String mbIpAddress, int mbPort, String eventClassName, String jsonFilePath) {
- this.mbIpAddress = mbIpAddress;
- this.mbPort = mbPort;
- this.eventClassName = eventClassName;
- this.jsonFilePath = jsonFilePath;
- }
-
- private Event jsonToEvent(String jsonFilePath) {
- FileInputStream fileInputStream = null;
- try {
- fileInputStream = new FileInputStream(new File(jsonFilePath));
- String json = IOUtils.toString(fileInputStream, "UTF-8");
- if (log.isDebugEnabled()) {
- log.debug(String.format("Json: %s", json));
- }
- Class eventClass = Class.forName(eventClassName);
- return (Event) new Gson().fromJson(json, eventClass);
- } catch (FileNotFoundException e) {
- if (log.isErrorEnabled()) {
- log.error(e);
- }
- throw new RuntimeException(String.format("Could not find json file %s", jsonFilePath));
- } catch (ClassNotFoundException e) {
- if (log.isErrorEnabled()) {
- log.error(e);
- }
- throw new RuntimeException(String.format("Event class name %s is not valid", eventClassName));
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error(e);
- }
- throw new RuntimeException(String.format("Could not read json file %s", jsonFilePath));
- }
- }
-
- public void run() throws JMSException, NamingException, IOException {
- if (log.isInfoEnabled()) {
- log.info("\nEvent publisher started");
- }
- Event event = jsonToEvent(jsonFilePath);
- publishEvent(event);
- }
-
-
- private void publishEvent(Event event) throws JMSException, NamingException, IOException {
- EventPublisher publisher = new EventPublisher(mbIpAddress, mbPort, org.apache.stratos.messaging.util.Constants.INSTANCE_STATUS_TOPIC);
- try {
- publisher.connect();
- publisher.publish(event);
- if (log.isInfoEnabled()) {
- log.info(String.format("Event %s published", eventClassName));
- }
- } finally {
- publisher.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java b/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java
deleted file mode 100644
index 818bfbb..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java
+++ /dev/null
@@ -1,67 +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.cartridge.agent.event.publisher;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Event publisher main class.
- */
-public class Main {
- private static final Log log = LogFactory.getLog(Main.class);
-
- public static void main(String[] args) {
- try {
- if (log.isInfoEnabled()) {
- log.info("Event publisher started");
- }
- if ((args != null) && (args.length == 4)) {
- EventPublisherClient client = new EventPublisherClient(args[0], Integer.parseInt(args[1]), args[2], args[3]);
- client.run();
- System.exit(0);
- } else {
- printInvalidArgs(args);
- }
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error("Could not publish event", e);
- }
- printInvalidArgs(args);
- }
- System.exit(-1);
- }
-
- private static void printInvalidArgs(String[] args) {
- if (log.isErrorEnabled()) {
- if(args != null) {
- StringBuilder builder = new StringBuilder();
- for(String arg : args) {
- builder.append("[" + arg + "] ");
- }
- log.error(String.format("Arguments %s not valid. Event publisher could not be started.", builder.toString()));
- }
- else {
- log.error("Arguments not found. Event publisher could not be started.");
- }
- log.error("Expected: mb-ip-address mb-port event-class-name event-json-file-path");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/resources/jndi.properties b/products/cartridge-agent/modules/event-publisher/src/main/resources/jndi.properties
deleted file mode 100644
index 7862087..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/resources/jndi.properties
+++ /dev/null
@@ -1,23 +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.
-#
-
-connectionfactoryName=topicConnectionfactory
-connectionfactory.topicConnectionfactory=amqp://admin:admin@carbon/carbon?brokerlist='tcp://MB-IP-ADDRESS:MB-PORT'
-java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory
-java.naming.provider.url=repository/conf/jndi.properties
\ No newline at end of file