diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java index 56b86d5d94..aadfd77ec3 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/BuildCmd.java @@ -34,6 +34,7 @@ import org.wso2.apimgt.gateway.cli.exception.ConfigParserException; import org.wso2.apimgt.gateway.cli.model.config.Config; import org.wso2.apimgt.gateway.cli.model.config.ContainerConfig; +import org.wso2.apimgt.gateway.cli.model.config.Etcd; import org.wso2.apimgt.gateway.cli.utils.GatewayCmdUtils; import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionBuilder; import org.wso2.apimgt.gateway.cli.utils.ToolkitLibExtractionUtils; @@ -111,6 +112,11 @@ public void execute() { try{ String toolkitConfigPath = GatewayCmdUtils.getMainConfigLocation(); init(projectName, toolkitConfigPath, deploymentConfigPath); + + Etcd etcd = new Etcd(); + etcd.setEtcdEnabled(GatewayCmdUtils.getEtcdEnabled(projectName)); + GatewayCmdUtils.setEtcd(etcd); + MgwDefinitionBuilder.build(projectName); CodeGenerator codeGenerator = new CodeGenerator(); ThrottlePolicyGenerator policyGenerator = new ThrottlePolicyGenerator(); diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java index ea2aeb14f7..59b4d210d7 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/ImportCmd.java @@ -299,6 +299,10 @@ public void execute() { throw new CLIRuntimeException(errorMsg); } + Etcd etcd = new Etcd(); + etcd.setEtcdEnabled(GatewayCmdUtils.getEtcdEnabled(projectName)); + GatewayCmdUtils.setEtcd(etcd); + List applicationPolicies = service.getApplicationPolicies(accessToken); List subscriptionPolicies = service.getSubscriptionPolicies(accessToken); diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/InitCmd.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/InitCmd.java index bb3d131f28..224fbb23b8 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/InitCmd.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/cmd/InitCmd.java @@ -54,6 +54,9 @@ public class InitCmd implements GatewayLauncherCmd { @Parameter(names = {"-d", "--deployment-config"}, hidden = true) private String deploymentConfigPath; + @Parameter(names = { "-etcd", "--enable-etcd" }, hidden = true, arity = 0) + private boolean isEtcdEnabled; + @Parameter(names = {"--help", "-h", "?"}, hidden = true, description = "for more information", help = true) private boolean helpFlag; @@ -83,6 +86,8 @@ public void execute() { // Extract the zipped ballerina platform and runtime ToolkitLibExtractionUtils.extractPlatformAndRuntime(); init(projectName, deploymentConfigPath); + //todo: remove the temporary solution + GatewayCmdUtils.saveEtcdEnabled(projectName, isEtcdEnabled); OUT.println("Project '" + projectName + "' is initialized successfully."); } diff --git a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java index 89e5bb8003..cefcb257af 100644 --- a/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java +++ b/components/micro-gateway-cli/src/main/java/org/wso2/apimgt/gateway/cli/utils/GatewayCmdUtils.java @@ -54,6 +54,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -75,6 +76,33 @@ public static void setEtcd(Etcd etcd) { GatewayCmdUtils.etcd = etcd; } + //todo: change this later after being finalized + public static void saveEtcdEnabled(String projectName, boolean isEnabled){ + createFileIfNotExist(getProjectGenDirectoryPath(projectName), "internal.conf"); + Map confMap = new HashMap<>(1); + confMap.put("isEtcdEnabled", String.valueOf(isEnabled)); + try { + writeMapToFile(confMap, getProjectGenDirectoryPath(projectName) + File.separator + "internal.conf"); + } catch (IOException e){ + throw new CLIInternalException("Error while writing etcdEnabled to the internal.conf file", e); + } + } + + public static boolean getEtcdEnabled(String projectName){ + String internalConfPath = getProjectGenDirectoryPath(projectName)+ File.separator + "internal.conf"; + if(!(new File(internalConfPath)).exists()){ + return false; + } + try{ + return Boolean.valueOf(readFileToMap(internalConfPath).get("isEtcdEnabled")); + } catch (IOException e){ + throw new CLIInternalException("Error while reading the internal.conf file", e); + } catch (ClassNotFoundException e) { + throw new CLIInternalException("Error while while reading the internal.conf file", e); + } + + } + public static Config getConfig() { return config; }