Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Viraj authored and Viraj committed Apr 29, 2019
2 parents 433f077 + 2d62159 commit 7e23250
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 167 deletions.
4 changes: 4 additions & 0 deletions components/micro-gateway-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<groupId>com.moandjiezana.toml</groupId>
<artifactId>toml4j</artifactId>
</dependency>
<dependency>
<groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import org.wso2.apimgt.gateway.cli.codegen.ThrottlePolicyGenerator;
import org.wso2.apimgt.gateway.cli.config.TOMLConfigParser;
import org.wso2.apimgt.gateway.cli.constants.GatewayCliConstants;
import org.wso2.apimgt.gateway.cli.exception.*;
import org.wso2.apimgt.gateway.cli.exception.CLIInternalException;
import org.wso2.apimgt.gateway.cli.exception.CLIRuntimeException;
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.MgwDefinitionUtils;
import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionBuilder;
import org.wso2.apimgt.gateway.cli.utils.ToolkitLibExtractionUtils;

import java.io.File;
Expand Down Expand Up @@ -83,7 +85,7 @@ public void execute() {
}

String projectName = GatewayCmdUtils.getSingleArgument(mainArgs);
projectName = projectName.replaceAll("[\\/\\\\]", "");
projectName = projectName.replaceAll("[/\\\\]", "");
File projectLocation = new File(GatewayCmdUtils.getProjectDirectoryPath(projectName));

if (!projectLocation.exists()) {
Expand Down Expand Up @@ -115,10 +117,9 @@ public void execute() {
etcd.setEtcdEnabled(GatewayCmdUtils.getEtcdEnabled(projectName));
GatewayCmdUtils.setEtcd(etcd);

MgwDefinitionUtils.configureMgwDefinition(projectName);
MgwDefinitionBuilder.build(projectName);
CodeGenerator codeGenerator = new CodeGenerator();
ThrottlePolicyGenerator policyGenerator = new ThrottlePolicyGenerator();
boolean changesDetected;

policyGenerator.generate(GatewayCmdUtils.getProjectGenSrcDirectoryPath(projectName) + File.separator
+ GatewayCliConstants.POLICY_DIR, projectName);
Expand All @@ -128,7 +129,7 @@ public void execute() {

//to indicate the api information which is not used in the code generation process, but included in
//definition.yaml
MgwDefinitionUtils.FindNotUsedAPIInformation();
MgwDefinitionBuilder.FindUnusedAPIInformation();
//Initializing the ballerina project and creating .bal folder.
InitHandler.initialize(Paths.get(GatewayCmdUtils.getProjectGenDirectoryPath(projectName)), null,
new ArrayList<>(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ public class Main {
private static final String JC_EXPECTED_A_VALUE_AFTER_PARAMETER_PREFIX = "Expected a value after parameter";
private static final String INTERNAL_ERROR_MESSAGE = "Internal error occurred while executing command.";
private static final String MICRO_GW = "micro-gw: ";
private static final Logger logger = LoggerFactory.getLogger(Main.class);

private static PrintStream outStream = System.err;

private static final Logger logger = LoggerFactory.getLogger(Main.class);

public static void main(String... args) {
try {
Optional<GatewayLauncherCmd> optionalInvokedCmd = getInvokedCmd(args);
Expand Down Expand Up @@ -105,37 +104,10 @@ private static Optional<GatewayLauncherCmd> getInvokedCmd(String... args) {
cmdParser.addCommand(GatewayCliCommands.IMPORT, importCmd);
importCmd.setParentCmdParser(cmdParser);

// AddAPICmd addAPICmd = new AddAPICmd();
// cmdParser.addCommand(GatewayCliCommands.ADD_API, addAPICmd);
// addAPICmd.setParentCmdParser(cmdParser);
//
// AddRouteCmd addRouteCmd = new AddRouteCmd();
// cmdParser.addCommand(GatewayCliCommands.ADD_ROUTE, addRouteCmd);
// addRouteCmd.setParentCmdParser(cmdParser);
//
// ListAPIsCmd listAPIsCmd = new ListAPIsCmd();
// cmdParser.addCommand(GatewayCliCommands.LIST_APIS, listAPIsCmd);
// listAPIsCmd.setParentCmdParser(cmdParser);
//
// ListResourcesCmd listResourcesCmd = new ListResourcesCmd();
// cmdParser.addCommand(GatewayCliCommands.LIST_RESOURCES, listResourcesCmd);
// listResourcesCmd.setParentCmdParser(cmdParser);
//
// DescResourceCmd descResourceCmd = new DescResourceCmd();
// cmdParser.addCommand(GatewayCliCommands.DESC_RESOURCE, descResourceCmd);
// descResourceCmd.setParentCmdParser(cmdParser);
//
// FunctionCmd functionCmd = new FunctionCmd();
// cmdParser.addCommand(GatewayCliCommands.FUNCTION,functionCmd);
// functionCmd.setParentCmdParser(cmdParser);

SetProjectCmd setProjectCmd = new SetProjectCmd();
cmdParser.addCommand(GatewayCliCommands.SET, setProjectCmd);
setProjectCmd.setParentCmdParser(cmdParser);

// UpdateRouteCmd updateRouteCmd = new UpdateRouteCmd();
// cmdParser.addCommand(GatewayCliCommands.UPDATE_ROUTE, updateRouteCmd);
// updateRouteCmd.setParentCmdParser(cmdParser);

Map<String, JCommander> commanderMap;
String parsedCmdName;
if (args.length != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void generate(String projectName, boolean overwrite)
Files.walk(Paths.get(openApiPath)).filter( path -> path.getFileName().toString().endsWith(".json"))
.forEach( path -> {
ExtendedAPI api = OpenAPICodegenUtils.generateAPIFromOpenAPIDef(path.toString());
String basepath = MgwDefinitionUtils.getBasePath(api.getName(), api.getVersion());
String basepath = MgwDefinitionBuilder.getBasePath(api.getName(), api.getVersion());
api.setContext(basepath);
BallerinaService definitionContext;
OpenAPICodegenUtils.setAdditionalConfigsDevFirst(api);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.wso2.apimgt.gateway.cli.constants;

import java.io.File;
import java.util.Collections;
import java.util.regex.Pattern;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

public class GatewayCliConstants {
public static final String PROJECT_CONF_DIR = "conf";
Expand Down Expand Up @@ -115,4 +115,5 @@ public class GatewayCliConstants {
public static final String API_METADATA_FILE = "api-metadata.yaml";
public static final String API_SWAGGER = "swagger.json";
public static final String PROJECT_FILE_NAME = ".PROJECT";
public static final String DEFINITION_SCHEMA_FILE = "definition-schema.json";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.apimgt.gateway.cli.model.mgwdefinition;
package org.wso2.apimgt.gateway.cli.model.definition;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -26,14 +26,14 @@
* This class represents the DTO for Single API in Microgateway Definition.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MgwAPIDefinition {
public class APIDefinition {
private String title;
private String version;
private EndpointListRouteDTO prodEpList;
private EndpointListRouteDTO sandEpList;
private String requestInterceptor;
private String responseInterceptor;
private MgwPathsDefinition pathsDefinition;
private PathsDefinition pathsDefinition;
private String security; //todo: bring enum
private APICorsConfigurationDTO corsConfiguration;
//to identify whether it has been used
Expand Down Expand Up @@ -94,11 +94,11 @@ public void setCorsConfiguration(APICorsConfigurationDTO corsConfiguration) {
}

@JsonProperty("resources")
public MgwPathsDefinition getPathsDefinition() {
public PathsDefinition getPathsDefinition() {
return pathsDefinition;
}

public void setPathsDefinition(MgwPathsDefinition pathsDefinition) {
public void setPathsDefinition(PathsDefinition pathsDefinition) {
this.pathsDefinition = pathsDefinition;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.apimgt.gateway.cli.model.mgwdefinition;
package org.wso2.apimgt.gateway.cli.model.definition;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -27,11 +27,11 @@
* This class represents the DTO for multiple APIs in Microgateway Definition.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MgwAPIsDefinition {
private Map<String, MgwAPIDefinition> apis = new LinkedHashMap<>();
public class APIDefinitions {
private Map<String, APIDefinition> apis = new LinkedHashMap<>();

@JsonAnySetter
public void setApis(String key, MgwAPIDefinition api) {
public void setApis(String key, APIDefinition api) {
apis.put(key, api);
}

Expand All @@ -40,16 +40,16 @@ public void setApis(String key, MgwAPIDefinition api) {
*
* @return map with (basepath, api information object)
*/
public Map<String, MgwAPIDefinition> getApisMap(){
public Map<String, APIDefinition> getApisMap() {
return apis;
}

public MgwAPIDefinition getApiFromBasepath(String basepath) {
public APIDefinition getApiFromBasepath(String basepath) {
return apis.get(basepath);
}

public String getBasepathFromAPI(String apiName, String apiVersion) {
for (Map.Entry<String, MgwAPIDefinition> apiEntry : apis.entrySet()) {
for (Map.Entry<String, APIDefinition> apiEntry : apis.entrySet()) {
if (apiEntry.getValue().getTitle().equals(apiName) && apiEntry.getValue().getVersion().equals(apiVersion)) {
//because if this method is called, it means that API information is utilized.
apiEntry.getValue().setIsDefinitionUsed(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.apimgt.gateway.cli.model.mgwdefinition;
package org.wso2.apimgt.gateway.cli.model.definition;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* This class represents the DTO for root in Microgateway Definition.
*/
public class MgwRootDefinition {
private MgwAPIsDefinition apis;

public class DefinitionConfig {
@JsonProperty("apis")
public MgwAPIsDefinition getApis() {
private APIDefinitions apis;

public APIDefinitions getApis() {
return apis;
}

public void setApis(MgwAPIsDefinition apis) {
public void setApis(APIDefinitions apis) {
this.apis = apis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.apimgt.gateway.cli.model.mgwdefinition;
package org.wso2.apimgt.gateway.cli.model.definition;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -26,7 +26,7 @@
* This class represents the DTO for Single Path in API in Microgateway Definition.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MgwEndpointListDefinition {
public class EndpointListDefinition {
private EndpointListRouteDTO prodEndpointList;
private EndpointListRouteDTO sandEndpointList;
private String requestInterceptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.apimgt.gateway.cli.model.mgwdefinition;
package org.wso2.apimgt.gateway.cli.model.definition;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -27,15 +27,15 @@
* This class represents the DTO for all the paths in API in Microgateway Definition.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MgwPathsDefinition {
private Map<String, MgwResourceDefinition> resources = new LinkedHashMap<>();
public class PathsDefinition {
private Map<String, ResourceDefinition> resources = new LinkedHashMap<>();

@JsonAnySetter
public void setResources(String key, MgwResourceDefinition path) {
public void setResources(String key, ResourceDefinition path) {
resources.put(key, path);
}

public MgwResourceDefinition getMgwResource(String path) {
public ResourceDefinition getMgwResource(String path) {
return resources.get(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.apimgt.gateway.cli.model.mgwdefinition;
package org.wso2.apimgt.gateway.cli.model.definition;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.LinkedHashMap;
import java.util.Map;

public class MgwResourceDefinition {
private Map<String, MgwEndpointListDefinition> operations = new LinkedHashMap<>();
public class ResourceDefinition {
private Map<String, EndpointListDefinition> operations = new LinkedHashMap<>();

@JsonAnySetter
public void setEndpoints(String key, MgwEndpointListDefinition endpoint) {
public void setEndpoints(String key, EndpointListDefinition endpoint) {
operations.put(key, endpoint);
}

public MgwEndpointListDefinition getEndpointListDefinition(String resourceName) {
public EndpointListDefinition getEndpointListDefinition(String resourceName) {
return operations.get(resourceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.wso2.apimgt.gateway.cli.utils.CodegenUtils;
import org.wso2.apimgt.gateway.cli.utils.GatewayCmdUtils;
import org.wso2.apimgt.gateway.cli.model.config.Etcd;
import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionUtils;
import org.wso2.apimgt.gateway.cli.utils.MgwDefinitionBuilder;

import java.util.AbstractMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -167,36 +167,36 @@ private void setPaths(OpenAPI openAPI) throws BallerinaServiceGenException {
operation.getValue().setOperationId(operationId);
//if it is the developer first approach
if (isDevFirst) {
String basePath = MgwDefinitionUtils.getBasePath(openAPI.getInfo().getTitle(),
String basePath = MgwDefinitionBuilder.getBasePath(openAPI.getInfo().getTitle(),
openAPI.getInfo().getVersion());
//to add resource level endpoint configuration
MgwEndpointConfigDTO epConfig = MgwDefinitionUtils.getResourceEpConfigForCodegen(basePath,
MgwEndpointConfigDTO epConfig = MgwDefinitionBuilder.getResourceEpConfigForCodegen(basePath,
path.getKey(), operation.getKey());
if (epConfig != null) {
operation.getValue().setEpConfigDTO(epConfig);
}
//todo: need to validate the existence of those functions
//to add request interceptor
String requestInterceptor = MgwDefinitionUtils.getRequestInterceptor(basePath, path.getKey(),
String requestInterceptor = MgwDefinitionBuilder.getRequestInterceptor(basePath, path.getKey(),
operation.getKey());
if (requestInterceptor != null) {
operation.getValue().setRequestInterceptor(requestInterceptor);
}
//to add response interceptor
String responseInterceptor = MgwDefinitionUtils.getResponseInterceptor(basePath, path.getKey(),
String responseInterceptor = MgwDefinitionBuilder.getResponseInterceptor(basePath, path.getKey(),
operation.getKey());
if (responseInterceptor != null) {
operation.getValue().setResponseInterceptor(responseInterceptor);
}
//to add throttle policy
String throttle_policy = MgwDefinitionUtils.getThrottlePolicy(basePath, path.getKey(),
String throttle_policy = MgwDefinitionBuilder.getThrottlePolicy(basePath, path.getKey(),
operation.getKey());
if (throttle_policy != null) {
operation.getValue().setResourceTier(throttle_policy);
}

//to add API level request interceptor
String apiRequestInterceptor = MgwDefinitionUtils.getApiRequestInterceptor(basePath);
String apiRequestInterceptor = MgwDefinitionBuilder.getApiRequestInterceptor(basePath);
if (apiRequestInterceptor != null) {
//if user specify the same interceptor function in both api level and resource level ignore
// api level interceptor
Expand All @@ -206,7 +206,7 @@ private void setPaths(OpenAPI openAPI) throws BallerinaServiceGenException {
}

//to add API level response interceptor
String apiResponseInterceptor = MgwDefinitionUtils.getApiResponseInterceptor(basePath);
String apiResponseInterceptor = MgwDefinitionBuilder.getApiResponseInterceptor(basePath);
if (apiResponseInterceptor != null) {
operation.getValue().setApiResponseInterceptor(apiResponseInterceptor);
}
Expand Down
Loading

0 comments on commit 7e23250

Please sign in to comment.