Java Code Examples for org.wso2.carbon.utils.multitenancy.MultitenantUtils#getAxis2RepositoryPath()
The following examples show how to use
org.wso2.carbon.utils.multitenancy.MultitenantUtils#getAxis2RepositoryPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CarbonRepositoryUtils.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Create and initialize a new DeploymentSynchronizer for the Carbon repository of the * specified tenant. This method first attempts to load the synchronizer configuration * from the registry. If a configuration does not exist in the registry, it will get the * configuration from the global ServerConfiguration of Carbon. Note that this method * does not start the created synchronizers. It only creates and initializes them using * the available configuration settings. * * @param tenantId ID of the tenant * @return a DeploymentSynchronizer instance or null if the synchronizer is disabled * @throws org.wso2.carbon.deployment.synchronizer.DeploymentSynchronizerException If an error occurs while initializing the synchronizer */ public static DeploymentSynchronizer newCarbonRepositorySynchronizer(int tenantId) throws DeploymentSynchronizerException { DeploymentSynchronizerConfiguration config = getActiveSynchronizerConfiguration(tenantId); if (config.isEnabled()) { String filePath = MultitenantUtils.getAxis2RepositoryPath(tenantId); ArtifactRepository artifactRepository = createArtifactRepository( config.getRepositoryType()); artifactRepository.init(tenantId); DeploymentSynchronizer synchronizer = DeploymentSynchronizationManager.getInstance(). createSynchronizer(tenantId, artifactRepository, filePath); synchronizer.setAutoCommit(config.isAutoCommit()); synchronizer.setAutoCheckout(config.isAutoCheckout()); synchronizer.setPeriod(config.getPeriod()); synchronizer.setUseEventing(config.isUseEventing()); if (log.isDebugEnabled()) { log.debug("Registered file path:" + filePath + " for tenant: " + tenantId); } return synchronizer; } return null; }
Example 2
Source File: GitBasedArtifactRepository.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * Called at tenant load to do initialization related to the tenant * * @param tenantId id of the tenant * @throws DeploymentSynchronizerException in case of an error */ public void init (int tenantId) throws DeploymentSynchronizerException { TenantGitRepositoryContext repoCtx = new TenantGitRepositoryContext(); String gitLocalRepoPath = MultitenantUtils.getAxis2RepositoryPath(tenantId); repoCtx.setTenantId(tenantId); repoCtx.setLocalRepoPath(gitLocalRepoPath); FileRepository localRepo = null; try { localRepo = new FileRepository(new File(gitLocalRepoPath + "/.git")); } catch (IOException e) { handleError("Error creating git local repository for tenant " + tenantId, e); } repoCtx.setLocalRepo(localRepo); repoCtx.setGit(new Git(localRepo)); repoCtx.setCloneExists(false); TenantGitRepositoryContextCache.getTenantRepositoryContextCache().cacheTenantGitRepoContext(tenantId, repoCtx); //provision a repository repositoryManager.provisionRepository(tenantId); //repositoryManager.addRepository(tenantId, url); repositoryManager.getUrlInformation(tenantId); repositoryManager.getCredentialsInformation(tenantId); }
Example 3
Source File: DeploymentSynchronizationManager.java From carbon-commons with Apache License 2.0 | 4 votes |
public DeploymentSynchronizer deleteSynchronizer(int tenantId) { String filePath = MultitenantUtils.getAxis2RepositoryPath(tenantId); synchronized (filePath.intern()) { return synchronizers.remove(filePath); } }
Example 4
Source File: SVNFileChecksumResolverUtil.java From carbon-commons with Apache License 2.0 | 4 votes |
/** * Resolves the checksum inconsistency in svn client when commit and update. * * @param errorMessage Error message which is captured by the SVNNotifyListener logError * method. */ public static void resolveChecksum(String errorMessage) { if(errorMessage.contains("Base checksum mismatch")) { int exIndex = errorMessage.indexOf("expected:"); int acIndex = errorMessage.indexOf("actual:"); int beginFile = errorMessage.indexOf("'", 0); int endFile = errorMessage.indexOf("'", beginFile +1); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); String axis2RepoPath = MultitenantUtils.getAxis2RepositoryPath(tenantId); // Append file separator at the end if not present. Usually tenant mode its not present. if((axis2RepoPath.length() -1) != axis2RepoPath.lastIndexOf(File.separator)) { axis2RepoPath = axis2RepoPath.concat(File.separator); } /* Expected and actual checksum values are interchanged in the exception trace in svn client side. */ String expectedChecksum = errorMessage.substring(acIndex+7, errorMessage.length()-1); String actualChecksum = errorMessage.substring(exIndex+9, acIndex); String filePath = errorMessage.substring(beginFile+1, endFile); String svnFile = SVN_FOLDER + File.separator + CHECKSUM_FILENAME; String newSvnFile = SVN_FOLDER + File.separator + CHECKSUM_TEMP_FILENAME; int fileNameStartIndex = filePath.lastIndexOf(File.separatorChar) + 1; String svnPath = filePath.substring(0, fileNameStartIndex); String fullSvnFilePath = axis2RepoPath + svnPath + svnFile; String fulltmpFilePath = axis2RepoPath + svnPath + newSvnFile; File errorFile = new File(fullSvnFilePath); File tmpFile = new File(fulltmpFilePath); log.debug("Trying to correct the checksum mismatch for SVN file:" +fullSvnFilePath+ "." + "Expected:" +expectedChecksum.trim()+ " but it is:" +actualChecksum.trim()); try (Reader fis = new FileReader(errorFile); BufferedReader bis = new BufferedReader(new InputStreamReader(new FileInputStream(errorFile))); BufferedWriter bw = new BufferedWriter(new FileWriter(tmpFile));) { String line; while((line = bis.readLine()) != null){ String plainLine = line.trim(); if(plainLine.contains(actualChecksum.trim())) { log.debug("Found checksum:"+actualChecksum.trim()+". Will be replaced " + "with:"+expectedChecksum.trim()); bw.write(expectedChecksum.trim()); }else { bw.write(line); } bw.newLine(); } } catch(Exception e){ log.error(e.getMessage()); } // Rename the tmp file and remove old file. if(errorFile.delete()){ log.debug("SVN file:" +fullSvnFilePath+ " modifying."); if(tmpFile.renameTo(errorFile)){ log.debug("SVN file:" +fullSvnFilePath+ " update successful."); }else { log.error("SVN file:" +fulltmpFilePath+ " update failed. Please check file permissions and allow for modification."); } }else { log.error("SVN file:" +fullSvnFilePath+ " unable to modify. Please check file permissions and allow for modification."); log.error("Unable to resolve checksum mismatch"); } } }
Example 5
Source File: CarbonRepositoryUtils.java From carbon-commons with Apache License 2.0 | 2 votes |
/** * Returns the Carbon/Axis2 repository path for the given ConfigurationContext * * @param cfgCtx A ConfigurationContext instance owned by super tenant or some other tenant * @return Axis2 repository path from which the configuration is read */ public static String getCarbonRepositoryFilePath(ConfigurationContext cfgCtx) { int tenantId = MultitenantUtils.getTenantId(cfgCtx); return MultitenantUtils.getAxis2RepositoryPath(tenantId); }