Skip to content

Commit

Permalink
Merge pull request #481 from VirajSalaka/pull-479
Browse files Browse the repository at this point in the history
Persist "is_etcd_enabled" variable during init command
  • Loading branch information
Rajith90 authored Apr 29, 2019
2 parents 2d62159 + 7e23250 commit 30bf90b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public void execute() {
throw new CLIRuntimeException(errorMsg);
}

Etcd etcd = new Etcd();
etcd.setEtcdEnabled(GatewayCmdUtils.getEtcdEnabled(projectName));
GatewayCmdUtils.setEtcd(etcd);

List<ApplicationThrottlePolicyDTO> applicationPolicies = service.getApplicationPolicies(accessToken);
List<SubscriptionThrottlePolicyDTO> subscriptionPolicies = service.getSubscriptionPolicies(accessToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String, String> 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;
}
Expand Down

0 comments on commit 30bf90b

Please sign in to comment.