Skip to content

Commit

Permalink
Merge pull request #14 from jegasmlm/master
Browse files Browse the repository at this point in the history
Version update to 2.0
  • Loading branch information
jegasmlm authored Mar 2, 2018
2 parents 1de8792 + 2d30413 commit 58ec3ad
Show file tree
Hide file tree
Showing 56 changed files with 1,474 additions and 763 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
build/
.sonar/
local.properties
Binary file modified .gradle/2.13/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified .gradle/2.13/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/2.13/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/2.13/taskArtifacts/taskArtifacts.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ If using **Maven**, add the following in your `pom.xml` file:
<dependency>
<groupId>io.kusanagi</groupId>
<artifactId>katana-sdk-java8</artifactId>
<version>1.3.0</version>
<version>2.0.0</version>
</dependency>
```

Or, if using **Gradle**, add the following in your `build.gradle` file:

```gradle
dependencies {
compile group: 'io.kusanagi', name: 'katana-sdk-java8', version: '1.3.0'
compile group: 'io.kusanagi', name: 'katana-sdk-java8', version: '2.0.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ apply plugin: 'signing'

group 'io.kusanagi'
archivesBaseName = "katana-sdk-java8"
version '1.3.0'
version '2.0.0'

mainClassName = 'io.kusanagi.katana.api.component.Component'

Expand Down
21 changes: 14 additions & 7 deletions src/main/java/io/kusanagi/katana/api/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,32 @@ public ServiceSchema getServiceSchema(String name, String version) {
}

/**
* send a string representation of the value argument to stdout as a "DEBUG" log, with a length limit on the value
* of 100,000 characters (not including the other elements of the log message, such as the timestamp), and return
* true. If the component is not running in debug mode this function MUST NOT send a log, and SHOULD return false.
* send a [string representation](#34-string-representation) of the `value` argument to `stdout` as a log, with a
* length limit on the value of **100,000** characters (not including the other elements of the log message, such
* as the timestamp).
*
* The `level` argument is the OPTIONAL value to use as the numeric Syslog severity level for the log message, as
* defined in RFC5424, which by default is **6**, representing the "Informational" level.
*
* @param value String to log
* @return true if the value gets logged
*/
public boolean log(String value) {
Logger.log(Logger.DEBUG, value);
public boolean log(String value, int level) {
Logger.log(level < 0 ? 0 : level > 7 ? 7 : level, value);
return true;
}

public boolean log(String value) {
return log(value, 6);
}

/**
*
* @return This function is only for use in an asynchronous implementation of the SDK, for any other implementation
* it MUST return false.
* it MUST throw an exception.
*/
public boolean done(){
return false;
throw new RuntimeException("SDK does not support async call to end action: Api.done()");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.kusanagi.katana.api.commands.common.CommandPayload;
import io.kusanagi.katana.api.component.Key;
import io.kusanagi.katana.sdk.Callee;
import io.kusanagi.katana.api.serializers.CalleeEntity;

/**
* Created by jega on 3/03/17.
*/
public class CallCommandPayload extends CommandPayload<Callee> {
public class CallCommandPayload extends CommandPayload<CalleeEntity> {

/**
* The semantics of the command
Expand Down Expand Up @@ -80,29 +80,29 @@ public String toString() {
'}';
}

public static class CallCommand extends CommandPayload.Command<Callee> {
public static class CallCommand extends CommandPayload.Command<CalleeEntity> {

/**
* The key/value arguments for the command, if no arguments exist this property SHOULD NOT be defined
*/
@JsonProperty(Key.COMMAND_ARGUMENT)
private Callee argument;
private CalleeEntity argument;

public CallCommand() {
//Empty constructor for serialization
}

public CallCommand(CallCommandPayload.CallCommand other) {
super(other);
this.argument = new Callee(other.argument);
this.argument = new CalleeEntity(other.argument);
}

@Override
public Callee getArgument() {
public CalleeEntity getArgument() {
return argument;
}

public void setArgument(Callee argument) {
public void setArgument(CalleeEntity argument) {
this.argument = argument;
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/io/kusanagi/katana/api/component/Arg.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ public class Arg {
public static final String ACTION_ARG = "--action";

/**
* short argument key for the switch, which if defined MUST disable all logs, even if -D or --debug is present.
* short argument key for An OPTIONAL switch, which if defined MUST enable logging support, where the value of the
* option specifies the numeric Syslog severity level
*/
public static final String SHORT_QUIET_ARG = "-q";
public static final String SHORT_LOG_ARG = "-L";

/**
* argument key for the switch, which if defined MUST disable all logs, even if -D or --debug is present.
* An OPTIONAL switch, which if defined MUST enable logging support, where the value of the option specifies the
* numeric Syslog severity level
*/
public static final String QUIET_ARG = "--quiet";
public static final String LOG_ARG = "--log-level";

private Arg() {

Expand Down
41 changes: 26 additions & 15 deletions src/main/java/io/kusanagi/katana/api/component/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.kusanagi.katana.api.replies.common.CommandReplyResult;
import io.kusanagi.katana.sdk.ActionSchema;
import io.kusanagi.katana.sdk.Callable;
import io.kusanagi.katana.sdk.Error;
import io.kusanagi.katana.api.serializers.ErrorEntity;
import io.kusanagi.katana.sdk.ServiceSchema;
import org.zeromq.ZMQ;

Expand Down Expand Up @@ -56,7 +56,7 @@ public abstract class Component<T extends Api, S extends CommandReplyResult, R e
new Option(new String[]{Arg.SHORT_DISABLE_COMPACT_NAMES_ARG, Arg.DISABLE_COMPACT_NAMES_ARG}, true, false, false),
new Option(new String[]{Arg.SHORT_DEBUG_ARG, Arg.DEBUG_ARG}, true, false, false),
new Option(new String[]{Arg.SHORT_ACTION_ARG, Arg.ACTION_ARG}, true, false, true),
new Option(new String[]{Arg.SHORT_QUIET_ARG, Arg.QUIET_ARG}, true, false, false),
new Option(new String[]{Arg.SHORT_LOG_ARG, Arg.LOG_ARG}, true, false, true),
};

private final String workerEndpoint;
Expand All @@ -81,7 +81,7 @@ public abstract class Component<T extends Api, S extends CommandReplyResult, R e

private String action;

private boolean quiet;
private int logLevel;

private Map<String, Callable<T>> resources;

Expand Down Expand Up @@ -128,7 +128,11 @@ public Component(String[] args) {
generateDefaultSocket();
}

if (isDebug() && !this.quiet) {
Logger.setComponent(this.getComponent());
Logger.setComponentName(this.getName());
Logger.setVersion(this.getVersion());
Logger.setFrameworkVersion(this.getFrameworkVersion());
if (isDebug()) {
Logger.activate();
} else {
Logger.deactivate();
Expand Down Expand Up @@ -181,8 +185,8 @@ public String getAction() {
return action;
}

public boolean isQuiet() {
return quiet;
public int getLogLevel() {
return logLevel;
}

// SDK METHODS
Expand Down Expand Up @@ -313,18 +317,25 @@ public void run() {
}

/**
* send a string representation of the value argument to stdout as a "DEBUG" log, with a length limit on the value
* of 100,000 characters (not including the other elements of the log message, such as the timestamp), and return
* true. If the component is not running in debug mode this function MUST NOT send a log, and SHOULD return false.
* send a [string representation](#34-string-representation) of the `value` argument to `stdout` as a log, with a
* length limit on the value of **100,000** characters (not including the other elements of the log message, such
* as the timestamp).
*
* The `level` argument is the OPTIONAL value to use as the numeric Syslog severity level for the log message, as
* defined in RFC5424, which by default is **6**, representing the "Informational" level.
*
* @param value String to log
* @return true if the value gets logged
*/
public boolean log(String value) {
Logger.log(Logger.DEBUG, value);
public boolean log(String value, int level) {
Logger.log(level < 0 ? 0 : level > 7 ? 7 : level, value);
return this.debug;
}

public boolean log(String value) {
return log(value, 6);
}

protected abstract void runShutdown();

private void setWorkers() {
Expand Down Expand Up @@ -406,7 +417,7 @@ public byte[][] onRequestReceived(String componentType, byte[] mappings, byte[]
protected abstract void runErrorCallback();

private static ErrorPayload getErrorPayload(Exception e) {
Error error = new Error();
ErrorEntity error = new ErrorEntity();
error.setMessage(e.getMessage());
error.setCode(1);
error.setStatus(Constants.INTERNAL_SERVER_ERROR_STATUS);
Expand Down Expand Up @@ -527,8 +538,8 @@ private void setMembers(List<Option> options) {
case Arg.SHORT_ACTION_ARG:
this.action = option.getValue();
break;
case Arg.SHORT_QUIET_ARG:
this.quiet = true;
case Arg.SHORT_LOG_ARG:
this.logLevel = Integer.valueOf(option.getValue());
break;
default:
Logger.log(Logger.ERROR, String.format(ExceptionMessage.UNSUPPORTED_PARAMETER, option.getNames()[0]));
Expand All @@ -550,7 +561,7 @@ public String toString() {
", debug=" + debug +
", var=" + var +
", action=" + action +
", quiet=" + quiet +
", logLevel=" + logLevel +
'}';
}
}
19 changes: 11 additions & 8 deletions src/main/java/io/kusanagi/katana/api/component/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public class Key {
public static final String ACTION_SCHEMA_TIMEOUT = "x";
public static final String ACTION_SCHEMA_ENTITY_PATH = "e";
public static final String ACTION_SCHEMA_PATH_DELIMITER = "d";
public static final String ACTION_SCHEMA_PRIMARY = "k";
public static final String ACTION_SCHEMA_COLLECTION = "c";
public static final String ACTION_SCHEMA_CALLS = "C";
public static final String ACTION_SCHEMA_DEFERRED_CALLS = "dc";
Expand All @@ -96,18 +95,19 @@ public class Key {
public static final String ACTION_SCHEMA_ENTITY = "E";
public static final String ACTION_SCHEMA_RELATIONS = "r";
public static final String ACTION_SCHEMA_RETURN_OBJECT = "rv";
public static final String ACTION_SCHEMA_TAGS = "t";

//Call
//CallEntity
public static final String CALL_DURATION = "D";
public static final String CALL_NAME = "n";
public static final String CALL_VERSION = "v";
public static final String CALL_ACTION = "a";
public static final String CALL_CALLER = "C";
public static final String CALL_GATEWAY = "g";
public static final String CALL_TIMEOUT = "t";
public static final String CALL_TIMEOUT = "x";
public static final String CALL_PARAMS = "p";

//Callee
//CalleeEntity
public static final String CALLEE_ACTION = "action";
public static final String CALLEE_CALLEE_INFO = "callee";
public static final String CALLEE_TRANSPORT = "transport";
Expand All @@ -117,9 +117,11 @@ public class Key {
//Entity Schema
public static final String ENTITY_SCHEMA_FIELD = "f";
public static final String ENTITY_SCHEMA_FIELDS = "F";
public static final String ENTITY_SCHEMA_NAME = "n";
public static final String ENTITY_SCHEMA_VALIDATE = "V";
public static final String ENTITY_SCHEMA_PRIMARY = "k";

//Error
//ErrorEntity
public static final String ERROR_MESSAGE = "m";
public static final String ERROR_CODE = "c";
public static final String ERROR_STATUS = "s";
Expand All @@ -130,6 +132,7 @@ public class Key {
public static final String FIELD_SCHEMA_OPTIONAL = "o";

//File
public static final String FILE_NAME = "n";
public static final String FILE_PATH = "p";
public static final String FILE_MIME = "m";
public static final String FILE_FILENAME = "f";
Expand Down Expand Up @@ -199,7 +202,7 @@ public class Key {
public static final String REQUEST_HTTP_REQUEST = "r";
public static final String REQUEST_REQUEST_CALL = "c";

//Request Call
//Request CallEntity
public static final String REQUEST_CALL_SERVICE = "s";
public static final String REQUEST_CALL_VERSION = "v";
public static final String REQUEST_CALL_ACTION = "a";
Expand All @@ -222,14 +225,14 @@ public class Key {
public static final String SERVICE_SCHEMA_HTTP_SCHEMA = "h";
public static final String SERVICE_SCHEMA_ACTION_SCHEMAS = "ac";

//Service Transaction
//Service TransactionEntity
public static final String SERVICE_TRANSACTION_NAME = "n";
public static final String SERVICE_TRANSACTION_VERSION = "v";
public static final String SERVICE_TRANSACTION_ACTION = "a";
public static final String SERVICE_TRANSACTION_CALLER = "c";
public static final String SERVICE_TRANSACTION_PARAMS = "p";

//Transaction
//TransactionEntity
public static final String TRANSACTION_COMMIT = "c";
public static final String TRANSACTION_ROLLBACK = "r";
public static final String TRANSACTION_COMPLETE = "C";
Expand Down
Loading

0 comments on commit 58ec3ad

Please sign in to comment.