stratos-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Isuru Perera <isu...@wso2.com>
Subject Fwd: [1/2] git commit: Fixing deployment paths for tenants
Date Sat, 18 Jan 2014 17:30:38 GMT
Sajith,

I guess you can use a constant in WSO2 Carbon for -1234 (Super Tenant ID),
right?

---------- Forwarded message ----------
From: <sajith@apache.org>
Date: Fri, Jan 17, 2014 at 12:47 PM
Subject: [1/2] git commit: Fixing deployment paths for tenants
To: commits@stratos.incubator.apache.org


Updated Branches:
  refs/heads/master b48bfcd96 -> 69ccd8803


Fixing deployment paths for tenants


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit:
http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/8e417ad7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/8e417ad7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/8e417ad7

Branch: refs/heads/master
Commit: 8e417ad7c8020bbcbd61e9c5edf0f4b06ead06e3
Parents: ec878b3
Author: Sajith Kariyawasam <sajith@wso2.com>
Authored: Fri Jan 17 12:46:29 2014 +0530
Committer: Sajith Kariyawasam <sajith@wso2.com>
Committed: Fri Jan 17 12:46:29 2014 +0530

----------------------------------------------------------------------
 .../git/impl/GitBasedArtifactRepository.java    | 41 +++++++++++++++++++-
 1 file changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8e417ad7/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/artifact/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
----------------------------------------------------------------------
diff --git
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/artifact/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/artifact/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
index fcd6a83..e8934ad 100644
---
a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/artifact/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
+++
b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/artifact/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
@@ -53,6 +53,8 @@ public class GitBasedArtifactRepository {
     //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 static String SUPER_TENANT_APP_PATH =
"/repository/deployment/server/";
+    private static String TENANT_PATH = "/repository/tenants/";

     private GitBasedArtifactRepository () {

@@ -81,8 +83,8 @@ public class GitBasedArtifactRepository {
         log.info("tenant " + tenantId);

         gitRepoCtx.setTenantId(tenantId);
-        gitRepoCtx.setGitLocalRepoPath(gitLocalRepoPath);
-               gitRepoCtx.setGitRemoteRepoUrl(gitRemoteRepoUrl);
+
 gitRepoCtx.setGitLocalRepoPath(getRepoPathForTenantId(tenantId,gitLocalRepoPath));
+        gitRepoCtx.setGitRemoteRepoUrl(gitRemoteRepoUrl);


gitRepoCtx.setRepoUsername(repositoryInformation.getRepoUsername());

gitRepoCtx.setRepoPassword(repositoryInformation.getRepoPassword());
@@ -113,6 +115,41 @@ public class GitBasedArtifactRepository {
         cacheGitRepoContext(tenantId, gitRepoCtx);
     }

+
+
+    // If tenant id is "-1234", then its super tenant, else tenant
+    private static String getRepoPathForTenantId(int tenantId,
+                       String gitLocalRepoPath) {
+
+       StringBuilder repoPathBuilder = new StringBuilder();
+
+       if(tenantId == -1234) {
+
repoPathBuilder.append(gitLocalRepoPath).append(SUPER_TENANT_APP_PATH);
+       } else {
+               // create folder with tenant id
+               createTenantDir(tenantId, gitLocalRepoPath);
+
repoPathBuilder.append(gitLocalRepoPath).append(TENANT_PATH).append(tenantId);
+       }
+
+               String repoPath = repoPathBuilder.toString();
+               log.info("Repo path returned : " + repoPath);
+               return repoPath;
+       }
+
+       private static void createTenantDir(int tenantId, String path) {
+               String dirPathName = path+TENANT_PATH+tenantId;
+               boolean dirStatus = new File(dirPathName).mkdir();
+               if(dirStatus){
+                       log.info("Successfully created directory
["+dirPathName+"] ");
+               }else {
+                       log.error("Directory creating failed in
["+dirPathName+"] ");
+               }
+       }
+
+
+
+
+
     /**
      * Checks if key based authentication (SSH) is required
      *




-- 
Isuru Perera
Senior Software Engineer | WSO2, Inc. | http://wso2.com/
Lean . Enterprise . Middleware

about.me/chrishantha

Mime
View raw message