Skip to content

Commit

Permalink
Merge pull request #3882 from chathuranga-jayanath-99/update-getting-…
Browse files Browse the repository at this point in the history
…governance-registry

Update governance registry dir path used for scheduled tasks
  • Loading branch information
arunans23 authored Jan 21, 2025
2 parents 7694cc6 + 2372351 commit b6ba6f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void init(Properties properties) {
addConfigProperty(name, value);
}
}
System.setProperty("mi.registry.gov", govRegistry);
log.debug("MI lightweight registry is initialized.");

initSecurityRepo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.wso2.micro.integrator.ntask.core.impl;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.micro.integrator.ntask.common.TaskException;
Expand All @@ -39,6 +40,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -54,11 +57,9 @@ public class FileBasedTaskRepository implements TaskRepository {
private static final Log log = LogFactory.getLog(FileBasedTaskRepository.class);

private static final String REG_TASK_BASE_PATH = "/repository/components/org.wso2.carbon.tasks";

private static final String REG_TASK_REPO_BASE_PATH = REG_TASK_BASE_PATH + "/" + "definitions";
private static final char URL_SEPARATOR_CHAR = '/';
private static String resourcePath =
getHome() + File.separator + "registry" + File.separator + "governance" + File.separator;
private static String resourcePath = getGovernanceRegistryPath();
private static Marshaller taskMarshaller;
private static Unmarshaller taskUnmarshaller;
private static final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
Expand All @@ -84,12 +85,21 @@ public FileBasedTaskRepository(int tenantId, String taskType) {
this.taskType = taskType;
}

private static String getHome() {
String carbonHome = System.getProperty("carbon.home");
if (carbonHome == null || "".equals(carbonHome) || ".".equals(carbonHome)) {
carbonHome = getSystemDependentPath(new File(".").getAbsolutePath());
private static String getGovernanceRegistryPath() {

String systemStoredGovRegistryPath = System.getProperty("mi.registry.gov");
try {
URI govRegistryUri = new URI(systemStoredGovRegistryPath);
String governanceRegistryPath = govRegistryUri.getPath();
if (governanceRegistryPath == null || "".equals(governanceRegistryPath) || ".".equals(governanceRegistryPath)) {
governanceRegistryPath = getSystemDependentPath(new File(".").getAbsolutePath()) +
File.separator + "registry" + File.separator + "governance" + File.separator;
}
return governanceRegistryPath;
} catch (URISyntaxException e) {
log.error("The governance registry path: '" + systemStoredGovRegistryPath + "' is not valid.");
return StringUtils.EMPTY;
}
return carbonHome;
}

private static String getSystemDependentPath(String path) {
Expand Down

0 comments on commit b6ba6f2

Please sign in to comment.