Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
build/
*.iml
classes
/bin/
.settings
.classpath
.project
/out/
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jdk:
services:
- docker
before_install:
- docker pull apiman/on-wildfly10:1.2.8.Final
- docker pull apiman/on-wildfly10:master
script:
- docker run -d -p 8080:8080 apiman/on-wildfly10:1.2.8.Final
- ./gradlew test -PintegrationTest --info --stacktrace
- docker run -d -p 8080:8080 apiman/on-wildfly10:master
- ./gradlew test -PintegrationTest --info --stacktrace
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

group 'io.apiman.cli'
version '0.2.5-SNAPSHOT'
version '0.3.0-SNAPSHOT'

buildscript {
repositories {
Expand All @@ -42,26 +42,28 @@ compileJava {
}

ext {
version_args4j = '2.33'
version_log4j = '2.5'
version_jcommander = '1.72'
version_log4j = '2.8.2'
version_guava = '19.0'
version_retrofit = '1.9.0'
version_jackson = '1.9.0'
version_jackson_yaml = '2.7.3'
version_modelmapper = '0.7.5'
version_commons_lang = '3.4'
version_guice = '4.0'
version_apiman = '1.3.1.Final'

// test dependencies
version_junit = '4.12'
version_ducttape = '1.0.5'
version_mockito = '1.10.19'
version_mockito = '2.8.47'
version_restassured = '2.9.0'
version_systemrules = '1.16.0'
version_hamcrest = '2.0.0.0'
}

dependencies {
compile "args4j:args4j:$version_args4j"
compile "com.beust:jcommander:$version_jcommander"
compile "org.apache.logging.log4j:log4j-core:$version_log4j"
compile "com.google.guava:guava:$version_guava"
compile "com.squareup.retrofit:retrofit:$version_retrofit"
Expand All @@ -70,6 +72,13 @@ dependencies {
compile "org.modelmapper:modelmapper:$version_modelmapper"
compile "org.apache.commons:commons-lang3:$version_commons_lang"
compile "com.google.inject:guice:$version_guice"

// apiman deps
compile "io.apiman:apiman-gateway-engine-beans:$version_apiman"
compile "io.apiman:apiman-common-plugin:$version_apiman"
compile "io.apiman:apiman-manager-api-core:$version_apiman"
runtime "io.apiman:apiman-distro-data:$version_apiman"
compile "io.apiman:apiman-gateway-api-rest:$version_apiman"

// route slf4j events to log4j2
compile "org.apache.logging.log4j:log4j-slf4j-impl:$version_log4j"
Expand All @@ -79,6 +88,7 @@ dependencies {
testCompile "org.mockito:mockito-core:$version_mockito"
testCompile "com.jayway.restassured:rest-assured:$version_restassured"
testCompile "com.github.stefanbirkner:system-rules:$version_systemrules"
testCompile "org.hamcrest:hamcrest-junit:$version_hamcrest"
}

jar {
Expand Down
70 changes: 44 additions & 26 deletions src/main/java/io/apiman/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,69 @@

package io.apiman.cli;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import com.google.common.collect.Lists;
import io.apiman.cli.command.api.command.ApiCommand;
import io.apiman.cli.command.core.AbstractCommand;
import io.apiman.cli.command.core.Command;
import io.apiman.cli.command.declarative.command.ApplyCommand;
import io.apiman.cli.command.gateway.command.GatewayCommand;
import io.apiman.cli.command.org.command.OrgCommand;
import io.apiman.cli.command.plugin.command.PluginCommand;
import io.apiman.cli.service.ManagementApiService;
import io.apiman.cli.exception.CommandException;
import io.apiman.cli.exception.ExitWithCodeException;
import io.apiman.cli.util.InjectionUtil;
import io.apiman.cli.util.LogUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.inject.Inject;
import java.util.List;
import java.util.Map;

/**
* The main class; the root of all Commands.
*
* @author Pete Cornish {@literal <[email protected]>}
*/
@Parameters(commandDescription = "Apiman CLI")
public class Cli extends AbstractCommand {
@Inject
public Cli(ManagementApiService managementApiService) {
super(managementApiService);
}

public static void main(String... args) {
InjectionUtil.getInjector().getInstance(Cli.class).run(Lists.newArrayList(args));
}
private static final Logger LOGGER = LogManager.getLogger(Cli.class);

@Override
protected void populateCommands(Map<String, Class<? extends Command>> commandMap) {
commandMap.put("org", OrgCommand.class);
commandMap.put("gateway", GatewayCommand.class);
commandMap.put("plugin", PluginCommand.class);
commandMap.put("api", ApiCommand.class);
commandMap.put("apply", ApplyCommand.class);
public void run(List<String> args, JCommander jc) {
jc.setAcceptUnknownOptions(false);
jc.setProgramName("apiman-cli");
jc.addObject(this);
build(jc);
try {
jc.parse(args.toArray(new String[]{}));
super.run(args, jc);
} catch (ParameterException | CommandException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(e.getMessage(), e);
} else {
if (e.getCause() == null) {
LOGGER.error(e.getMessage());
} else {
LOGGER.error("{}: {}", e.getMessage(), e.getCause().getMessage());
}
}
printUsage(jc, false);
} catch (ExitWithCodeException ec) {
// print the message and exit with the given code
LogUtil.OUTPUT.error(ec.getMessage());
if (ec.isPrintUsage()) {
printUsage(jc, ec.getExitCode());
} else {
System.exit(ec.getExitCode());
}
}
}

@Override
protected String getCommandDescription() {
return "apiman-cli";
protected void populateCommands(Map<String, Class<? extends Command>> commandMap) {
commandMap.put("manager", ManagerCli.class);
commandMap.put("gateway", GatewayCli.class);
}

@Override
public String getCommandName() {
return "apiman";
public static void main(String... args) {
InjectionUtil.getInjector().getInstance(Cli.class).run(Lists.newArrayList(args), new JCommander());
}
}
48 changes: 48 additions & 0 deletions src/main/java/io/apiman/cli/GatewayCli.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.apiman.cli;

import com.beust.jcommander.Parameters;
import io.apiman.cli.command.core.AbstractCommand;
import io.apiman.cli.command.core.Command;
import io.apiman.cli.gatewayapi.command.GatewayOrgCommand;
import io.apiman.cli.gatewayapi.command.GatewayStatusCommand;
import io.apiman.cli.gatewayapi.command.api.GatewayApiCommand;
import io.apiman.cli.gatewayapi.command.client.GatewayClientCommand;
import io.apiman.cli.gatewayapi.command.generate.Generate;
import io.apiman.cli.gatewayapi.declarative.command.GatewayApplyCommand;

import java.util.Map;

/**
* Root of Gateway commands.
*
* @author Marc Savy {@literal <[email protected]>}
*/
@Parameters(commandDescription = "Interact with an Apiman Gateway directly")
public class GatewayCli extends AbstractCommand {

@Override
protected void populateCommands(Map<String, Class<? extends Command>> commandMap) {
commandMap.put("generate", Generate.class);
commandMap.put("apply", GatewayApplyCommand.class);
commandMap.put("org", GatewayOrgCommand.class);
commandMap.put("api", GatewayApiCommand.class);
commandMap.put("client", GatewayClientCommand.class);
commandMap.put("status", GatewayStatusCommand.class);
}
}
48 changes: 48 additions & 0 deletions src/main/java/io/apiman/cli/ManagerCli.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2016 Pete Cornish
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.apiman.cli;

import com.beust.jcommander.Parameters;
import io.apiman.cli.command.core.AbstractCommand;
import io.apiman.cli.command.core.Command;
import io.apiman.cli.managerapi.command.api.command.ApiCommand;
import io.apiman.cli.managerapi.command.gateway.command.GatewayCommand;
import io.apiman.cli.managerapi.command.org.command.OrgCommand;
import io.apiman.cli.managerapi.command.plugin.command.PluginCommand;
import io.apiman.cli.managerapi.declarative.command.ManagerApplyCommand;

import java.util.Map;

/**
* The main class; the root of all Manager Commands.
*
* @author Pete Cornish {@literal <[email protected]>}
*/

@Parameters(commandDescription = "Interact with the Apiman Manager")
public class ManagerCli extends AbstractCommand {

@Override
protected void populateCommands(Map<String, Class<? extends Command>> commandMap) {
commandMap.put("org", OrgCommand.class);
commandMap.put("gateway", GatewayCommand.class);
commandMap.put("plugin", PluginCommand.class);
commandMap.put("api", ApiCommand.class);
commandMap.put("apply", ManagerApplyCommand.class);
}

}
31 changes: 31 additions & 0 deletions src/main/java/io/apiman/cli/annotations/CommandAvailableSince.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2017 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.apiman.cli.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Marc Savy {@literal <[email protected]>}
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface CommandAvailableSince {
String value();
}
16 changes: 16 additions & 0 deletions src/main/java/io/apiman/cli/command/api/model/ApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ public ApiConfig(String endpoint, String endpointType, boolean publicApi, List<A
this.gateways = gateways;
}

public List<ApiGateway> getGateways() {
return gateways;
}

public String getEndpoint() {
return endpoint;
}

public String getEndpointType() {
return endpointType;
}

public EndpointProperties getEndpointProperties() {
return endpointProperties;
}

public void setGateways(ArrayList<ApiGateway> gateways) {
this.gateways = gateways;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/apiman/cli/command/api/model/ApiGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public ApiGateway() {
public ApiGateway(String gatewayId) {
this.gatewayId = gatewayId;
}

public String getGatewayId() {
return gatewayId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package io.apiman.cli.command.api.model;

import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -53,4 +58,19 @@ public void setUsername(String username) {
public void setPassword(String password) {
this.password = password;
}

public Map<String, String> toMap() {
Map<String, String> map = new LinkedHashMap<>();
for (Field field : this.getClass().getDeclaredFields()) {
try {
if (field.isAnnotationPresent(JsonProperty.class)) {
JsonProperty annotation = field.getAnnotation(JsonProperty.class);
map.put(annotation.value(), Objects.toString(field.get(this)));
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return map;
}
}
Loading