Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge from master

  • Loading branch information...
commit 81d04b5ebaa5037ee4b8fbfd1f21e31c9765df99 2 parents aaf3c62 + 05fc15c
@richard-julien authored
Showing with 568 additions and 109 deletions.
  1. +1 −1  .gitignore
  2. +22 −0 LICENSE
  3. +72 −0 README.md
  4. +28 −40 client/src/main/java/io/iron/ironworker/client/APIClient.java
  5. +96 −40 client/src/main/java/io/iron/ironworker/client/Client.java
  6. +17 −0 client/src/main/java/io/iron/ironworker/client/builders/PaginationOptions.java
  7. +28 −0 client/src/main/java/io/iron/ironworker/client/builders/PaginationOptionsObject.java
  8. +29 −0 client/src/main/java/io/iron/ironworker/client/builders/Params.java
  9. +24 −0 client/src/main/java/io/iron/ironworker/client/builders/ParamsObject.java
  10. +18 −0 client/src/main/java/io/iron/ironworker/client/builders/TaskOptions.java
  11. +34 −0 client/src/main/java/io/iron/ironworker/client/builders/TaskOptionsObject.java
  12. +14 −0 client/src/main/java/io/iron/ironworker/client/builders/TaskProgressOptions.java
  13. +28 −0 client/src/main/java/io/iron/ironworker/client/builders/TaskProgressOptionsObject.java
  14. +23 −2 client/src/main/java/io/iron/ironworker/client/entities/BaseEntity.java
  15. +10 −10 client/src/main/java/io/iron/ironworker/client/entities/CodeEntity.java
  16. +16 −16 client/src/main/java/io/iron/ironworker/client/entities/CodeRevisionEntity.java
  17. +108 −0 client/src/main/java/io/iron/ironworker/client/entities/TaskEntity.java
View
2  .gitignore
@@ -2,4 +2,4 @@
*.iml
**/target/*
.gitignore.swp
-.DS_Store
+.DS_Store
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Iron.io, Inc
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
72 README.md
@@ -0,0 +1,72 @@
+# Basic Usage
+
+Visit http://iron.io for more details.
+
+This is very basic guide. Note that this library supports all IronWorker API features, it just lacks documentation.
+
+## Create Client
+
+It'll be used for all IronWorker interactions.
+
+```java
+import io.iron.ironworker.client.Client;
+
+Client client = new Client("IRON_IO_TOKEN", "IRON_IO_PROJECT_ID");
+```
+
+## Create Code Package
+
+This isn't implemented in this library yet, so you need to create zip which will contain all jars you need and runner.rb which will simply run java executable.
+
+```ruby
+root = nil
+
+($*.length - 2).downto(0) do |i|
+ root = $*[i + 1] if $*[i] == '-d'
+end
+
+Dir.chdir(root)
+
+puts `java -jar MyWorker.jar -cp Xerces.jar`
+
+```
+
+## Upload Code Package
+
+You need to specify name by which you'll call your worker later and path to zip created at previous step.
+
+```java
+import io.iron.ironworker.client.codes.JavaCode;
+
+JavaCode code = new JavaCode("MyWorker", "path/to/MyWorker.zip");
+client.createCode(code);
+```
+
+## Run It
+
+Prefered way is to use provided builders like Params or TaskOptions, but you can fall back and pass Map<String, Object> instead.
+
+```java
+import io.iron.ironworker.client.entities.TaskEntity;
+import io.iron.ironworker.client.builders.Params;
+import io.iron.ironworker.client.builders.TaskOptions;
+
+// specififying some options
+TaskEntity t = client.createTask("MyWorker",
+ Params.add("param", 13).add("another", "value"),
+ TaskOptions.priority(1).delay(60));
+
+// alternate params syntax
+client.createTask("MyWorker", Params.create("param", 13, "another", "value"));
+```
+
+## Get Results
+
+At the moment entities just hold data, you need to call client yourself.
+
+```java
+ t = client.getTask(t.getId()); // update information
+ String status = t.getStatus();
+
+ String log = client.getTaskLog(t.getId());
+```
View
68 client/src/main/java/io/iron/ironworker/client/APIClient.java
@@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import io.iron.ironworker.client.builders.Params;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
@@ -24,7 +25,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -273,8 +273,8 @@ private JsonObject parseResponseAsJson(HttpResponse response) throws APIExceptio
return (new JsonParser()).parse(new InputStreamReader(parseResponseGeneral(response))).getAsJsonObject();
}
- public JsonObject codesList(Map<String, Object> params) throws APIException {
- return parseResponseAsJson(doGetRequest(String.format("projects/%s/codes", projectId), params));
+ public JsonObject codesList(Map<String, Object> options) throws APIException {
+ return parseResponseAsJson(doGetRequest(String.format("projects/%s/codes", projectId), options));
}
public JsonObject codesGet(String id) throws APIException {
@@ -282,57 +282,49 @@ public JsonObject codesGet(String id) throws APIException {
}
public JsonObject codesCreate(String name, String file, String runtime, String runner) throws APIException {
- Map<String, Object> params = new HashMap<String, Object>();
-
- params.put("name", name);
- params.put("runtime", runtime);
- params.put("file_name", runner);
-
File f = new File(file);
if (!f.exists()) {
throw new APIException("File " + file + " not found", null);
}
- return parseResponseAsJson(doFileRequest(String.format("projects/%s/codes", projectId), (new Gson()).toJson(params), f));
+ String data = (new Gson()).toJson(Params.create("name", name, "runtime", runtime, "file_name", runner));
+
+ return parseResponseAsJson(doFileRequest(String.format("projects/%s/codes", projectId), data, f));
}
public JsonObject codesDelete(String id) throws APIException {
return parseResponseAsJson(doDeleteRequest(String.format("projects/%s/codes/%s", projectId, id), null));
}
- public JsonObject codesRevisions(String id, Map<String, Object> params) throws APIException {
- return parseResponseAsJson(doGetRequest(String.format("projects/%s/codes/%s/revisions", projectId, id), params));
+ public JsonObject codesRevisions(String id, Map<String, Object> options) throws APIException {
+ return parseResponseAsJson(doGetRequest(String.format("projects/%s/codes/%s/revisions", projectId, id), options));
}
- public byte[] codesDownload(String id, Map<String, Object> params) throws APIException {
- return parseResponseAsByteArray(doGetRequest(String.format("projects/%s/codes/%s/download", projectId, id), params));
+ public byte[] codesDownload(String id, Map<String, Object> options) throws APIException {
+ return parseResponseAsByteArray(doGetRequest(String.format("projects/%s/codes/%s/download", projectId, id), options));
}
- public JsonObject tasksList(Map<String, Object> params) throws APIException {
- return parseResponseAsJson(doGetRequest(String.format("projects/%s/tasks", projectId), params));
+ public JsonObject tasksList(Map<String, Object> options) throws APIException {
+ return parseResponseAsJson(doGetRequest(String.format("projects/%s/tasks", projectId), options));
}
public JsonObject tasksGet(String id) throws APIException {
return parseResponseAsJson(doGetRequest(String.format("projects/%s/tasks/%s", projectId, id), null));
}
- public JsonObject tasksCreate(String code_name, String payload, Map<String, Object> params) throws APIException {
- Map<String, Object> task = new HashMap<String, Object>();
+ public JsonObject tasksCreate(String code_name, String payload, Map<String, Object> options) throws APIException {
+ Map<String, Object> task = Params.create("code_name", code_name, "payload", payload);
- task.put("code_name", code_name);
- task.put("payload", payload);
- task.putAll(params);
+ if (options != null) {
+ task.putAll(options);
+ }
List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
tasks.add(task);
- Map<String, List<Map<String, Object>>> fullParams = new HashMap<String, List<Map<String, Object>>>();
-
- fullParams.put("tasks", tasks);
-
- return parseResponseAsJson(doPostRequest(String.format("projects/%s/tasks", projectId), (new Gson()).toJson(fullParams)));
+ return parseResponseAsJson(doPostRequest(String.format("projects/%s/tasks", projectId), (new Gson()).toJson(Params.create("tasks", tasks))));
}
public JsonObject tasksCancel(String id) throws APIException {
@@ -347,34 +339,30 @@ public String tasksLog(String id) throws APIException {
return parseResponseAsString(doGetRequest(String.format("projects/%s/tasks/%s/log", projectId, id), null));
}
- public JsonObject tasksSetProgress(String id, Map<String, Object> params) throws APIException {
- return parseResponseAsJson(doPostRequest(String.format("projects/%s/tasks/%s/progress", projectId, id), (new Gson()).toJson(params)));
+ public JsonObject tasksSetProgress(String id, Map<String, Object> options) throws APIException {
+ return parseResponseAsJson(doPostRequest(String.format("projects/%s/tasks/%s/progress", projectId, id), (new Gson()).toJson(options)));
}
- public JsonObject schedulesList(Map<String, Object> params) throws APIException {
- return parseResponseAsJson(doGetRequest(String.format("projects/%s/schedules", projectId), params));
+ public JsonObject schedulesList(Map<String, Object> options) throws APIException {
+ return parseResponseAsJson(doGetRequest(String.format("projects/%s/schedules", projectId), options));
}
public JsonObject schedulesGet(String id) throws APIException {
return parseResponseAsJson(doGetRequest(String.format("projects/%s/schedules/%s", projectId, id), null));
}
- public JsonObject schedulesCreate(String code_name, String payload, Map<String, Object> params) throws APIException {
- Map<String, Object> schedule = new HashMap<String, Object>();
+ public JsonObject schedulesCreate(String code_name, String payload, Map<String, Object> options) throws APIException {
+ Map<String, Object> schedule = Params.create("code_name", code_name, "payload", payload);
- schedule.put("code_name", code_name);
- schedule.put("payload", payload);
- schedule.putAll(params);
+ if (options != null) {
+ schedule.putAll(options);
+ }
List<Map<String, Object>> schedules = new ArrayList<Map<String, Object>>();
schedules.add(schedule);
- Map<String, List<Map<String, Object>>> fullParams = new HashMap<String, List<Map<String, Object>>>();
-
- fullParams.put("schedules", schedules);
-
- return parseResponseAsJson(doPostRequest(String.format("projects/%s/schedules", projectId), (new Gson()).toJson(fullParams)));
+ return parseResponseAsJson(doPostRequest(String.format("projects/%s/schedules", projectId), (new Gson()).toJson(Params.create("schedules", schedule))));
}
public JsonObject schedulesCancel(String id) throws APIException {
View
136 client/src/main/java/io/iron/ironworker/client/Client.java
@@ -1,10 +1,13 @@
package io.iron.ironworker.client;
+import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import io.iron.ironworker.client.builders.*;
import io.iron.ironworker.client.codes.BaseCode;
import io.iron.ironworker.client.entities.CodeEntity;
import io.iron.ironworker.client.entities.CodeRevisionEntity;
+import io.iron.ironworker.client.entities.TaskEntity;
import java.util.ArrayList;
import java.util.HashMap;
@@ -21,9 +24,9 @@ public Client(String token, String projectId) {
public APIClient getAPI() {
return api;
}
-
- private List<CodeEntity> getCodes(Map<String, Object> params) throws APIException {
- JsonObject codes = api.codesList(params);
+
+ public List<CodeEntity> getCodes(Map<String, Object> options) throws APIException {
+ JsonObject codes = api.codesList(options);
List<CodeEntity> codesList = new ArrayList<CodeEntity>();
@@ -34,25 +37,12 @@ public APIClient getAPI() {
return codesList;
}
- public List<CodeEntity> getCodes() throws APIException {
- return getCodes(null);
- }
-
- public List<CodeEntity> getCodes(int page) throws APIException {
- Map<String, Object> params = new HashMap<String, Object>();
-
- params.put("page", page);
-
- return getCodes(params);
+ public List<CodeEntity> getCodes(PaginationOptionsObject options) throws APIException {
+ return getCodes(options.create());
}
- public List<CodeEntity> getCodes(int page, int perPage) throws APIException {
- Map<String, Object> params = new HashMap<String, Object>();
-
- params.put("page", page);
- params.put("per_page", perPage);
-
- return getCodes(params);
+ public List<CodeEntity> getCodes() throws APIException {
+ return getCodes((Map<String, Object>) null);
}
public CodeEntity getCode(String codeId) throws APIException {
@@ -67,8 +57,8 @@ public void deleteCode(String codeId) throws APIException {
api.codesDelete(codeId);
}
- private List<CodeRevisionEntity> getCodeRevisions(String codeId, Map<String, Object> params) throws APIException {
- JsonObject codeRevisions = api.codesRevisions(codeId, params);
+ public List<CodeRevisionEntity> getCodeRevisions(String codeId, Map<String, Object> options) throws APIException {
+ JsonObject codeRevisions = api.codesRevisions(codeId, options);
List<CodeRevisionEntity> codeRevisionsList = new ArrayList<CodeRevisionEntity>();
@@ -79,40 +69,106 @@ public void deleteCode(String codeId) throws APIException {
return codeRevisionsList;
}
+ public List<CodeRevisionEntity> getCodeRevisions(String codeId, PaginationOptionsObject options) throws APIException {
+ return getCodeRevisions(codeId, options.create());
+ }
+
public List<CodeRevisionEntity> getCodeRevisions(String codeId) throws APIException {
- return getCodeRevisions(codeId, null);
+ return getCodeRevisions(codeId, (Map<String, Object>) null);
}
- public List<CodeRevisionEntity> getCodeRevisions(String codeId, int page) throws APIException {
- Map<String, Object> params = new HashMap<String, Object>();
+ public byte[] downloadCode(String codeId, Map<String, Object> options) throws APIException {
+ return api.codesDownload(codeId, options);
+ }
- params.put("page", page);
+ public byte[] downloadCode(String codeId, int revision) throws APIException {
+ return downloadCode(codeId, Params.create("revision", revision));
+ }
- return getCodeRevisions(codeId, params);
+ public byte[] downloadCode(String codeId) throws APIException {
+ return downloadCode(codeId, null);
}
- public List<CodeRevisionEntity> getCodeRevisions(String codeId, int page, int perPage) throws APIException {
- Map<String, Object> params = new HashMap<String, Object>();
+ public List<TaskEntity> getTasks(Map<String, Object> options) throws APIException {
+ JsonObject tasks = api.tasksList(options);
+
+ List<TaskEntity> tasksList = new ArrayList<TaskEntity>();
+
+ for (JsonElement task : tasks.get("tasks").getAsJsonArray()) {
+ tasksList.add(TaskEntity.fromJsonObject(task.getAsJsonObject()));
+ }
+
+ return tasksList;
+ }
- params.put("page", page);
- params.put("per_page", perPage);
+ public List<TaskEntity> getTasks(PaginationOptionsObject options) throws APIException {
+ return getTasks(options.create());
+ }
- return getCodeRevisions(codeId, params);
+ public List<TaskEntity> getTasks() throws APIException {
+ return getTasks((Map<String, Object>) null);
}
- private byte[] downloadCode(String codeId, Map<String, Object> params) throws APIException {
- return api.codesDownload(codeId, params);
+ public TaskEntity getTask(String taskId) throws APIException {
+ return TaskEntity.fromJsonObject(api.tasksGet(taskId));
}
- public byte[] downloadCode(String codeId) throws APIException {
- return downloadCode(codeId, null);
+ public TaskEntity createTask(String codeName, Map<String, Object> params, Map<String, Object> options) throws APIException {
+ if (params == null) {
+ params = new HashMap<String, Object>();
+ }
+
+ JsonObject tasks = api.tasksCreate(codeName, (new Gson()).toJson(Params.create("token", api.getToken(), "project_id", api.getProjectId(), "params", params)), options);
+ JsonObject task = tasks.get("tasks").getAsJsonArray().get(0).getAsJsonObject();
+
+ return TaskEntity.fromJsonObject(task);
}
- public byte[] downloadCode(String codeId, int revision) throws APIException {
- Map<String, Object> params = new HashMap<String, Object>();
+ public TaskEntity createTask(String codeName, Map<String, Object> params, TaskOptionsObject options) throws APIException {
+ return createTask(codeName, params, options.create());
+ }
+
+ public TaskEntity createTask(String codeName, ParamsObject params, Map<String, Object> options) throws APIException {
+ return createTask(codeName, params.create(), options);
+ }
+
+ public TaskEntity createTask(String codeName, ParamsObject params, TaskOptionsObject options) throws APIException {
+ return createTask(codeName, params.create(), options.create());
+ }
+
+ public TaskEntity createTask(String codeName, Map<String, Object> params) throws APIException {
+ return createTask(codeName, params, (Map<String, Object>) null);
+ }
+
+ public TaskEntity createTask(String codeName, ParamsObject params) throws APIException {
+ return createTask(codeName, params.create(), (Map<String, Object>) null);
+ }
+
+ public TaskEntity createTask(String codeName) throws APIException {
+ return createTask(codeName, (Map<String, Object>) null, (Map<String, Object>) null);
+ }
+
+ public void cancelTask(String taskId) throws APIException {
+ api.tasksCancel(taskId);
+ }
+
+ public void cancelAllTasks(String codeId) throws APIException {
+ api.tasksCancelAll(codeId);
+ }
+
+ public String getTaskLog(String taskId) throws APIException {
+ return api.tasksLog(taskId);
+ }
+
+ public void setTaskProgress(String taskId, Map<String, Object> options) throws APIException {
+ api.tasksSetProgress(taskId, options);
+ }
- params.put("revision", revision);
+ public void setTaskProgress(String taskId, TaskProgressOptionsObject options) throws APIException {
+ api.tasksSetProgress(taskId, options.create());
+ }
- return downloadCode(codeId, params);
+ public void setTaskProgress(String taskId) throws APIException {
+ setTaskProgress(taskId, (Map<String, Object>) null);
}
}
View
17 client/src/main/java/io/iron/ironworker/client/builders/PaginationOptions.java
@@ -0,0 +1,17 @@
+package io.iron.ironworker.client.builders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class PaginationOptions {
+ public static PaginationOptionsObject page(int page) {
+ return (new PaginationOptionsObject()).page(page);
+ }
+
+ public static PaginationOptionsObject perPage(int perPage) {
+ return (new PaginationOptionsObject()).perPage(perPage);
+ }
+
+ protected PaginationOptions() {
+ }
+}
View
28 client/src/main/java/io/iron/ironworker/client/builders/PaginationOptionsObject.java
@@ -0,0 +1,28 @@
+package io.iron.ironworker.client.builders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class PaginationOptionsObject {
+ private Map<String, Object> options;
+
+ public PaginationOptionsObject() {
+ options = new HashMap<String, Object>();
+ }
+
+ public PaginationOptionsObject page(int page) {
+ options.put("page", page);
+
+ return this;
+ }
+
+ public PaginationOptionsObject perPage(int perPage) {
+ options.put("per_page", perPage);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return options;
+ }
+}
View
29 client/src/main/java/io/iron/ironworker/client/builders/Params.java
@@ -0,0 +1,29 @@
+package io.iron.ironworker.client.builders;
+
+import io.iron.ironworker.client.APIException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Params {
+ public static Map<String, Object> create(Object... os) throws APIException {
+ if (os.length % 2 != 0) {
+ throw new APIException("Odd params number", null);
+ }
+
+ Map<String, Object> params = new HashMap<String, Object>();
+
+ for (int i = 0; i < os.length; i += 2) {
+ params.put(os[i].toString(), os[i + 1]);
+ }
+
+ return params;
+ }
+
+ public static ParamsObject add(String key, Object value) {
+ return (new ParamsObject()).add(key, value);
+ }
+
+ protected Params() {
+ }
+}
View
24 client/src/main/java/io/iron/ironworker/client/builders/ParamsObject.java
@@ -0,0 +1,24 @@
+package io.iron.ironworker.client.builders;
+
+import io.iron.ironworker.client.APIException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ParamsObject {
+ private Map<String, Object> params;
+
+ public ParamsObject() {
+ params = new HashMap<String, Object>();
+ }
+
+ public ParamsObject add(String key, Object value) {
+ params.put(key, value);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return params;
+ }
+}
View
18 client/src/main/java/io/iron/ironworker/client/builders/TaskOptions.java
@@ -0,0 +1,18 @@
+package io.iron.ironworker.client.builders;
+
+public class TaskOptions {
+ public static TaskOptionsObject priority(int priority) {
+ return (new TaskOptionsObject()).priority(priority);
+ }
+
+ public static TaskOptionsObject timeout(int timeout) {
+ return (new TaskOptionsObject()).timeout(timeout);
+ }
+
+ public static TaskOptionsObject delay(int delay) {
+ return (new TaskOptionsObject()).delay(delay);
+ }
+
+ protected TaskOptions() {
+ }
+}
View
34 client/src/main/java/io/iron/ironworker/client/builders/TaskOptionsObject.java
@@ -0,0 +1,34 @@
+package io.iron.ironworker.client.builders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TaskOptionsObject {
+ private Map<String, Object> options;
+
+ public TaskOptionsObject() {
+ options = new HashMap<String, Object>();
+ }
+
+ public TaskOptionsObject priority(int priority) {
+ options.put("priority", priority);
+
+ return this;
+ }
+
+ public TaskOptionsObject timeout(int timeout) {
+ options.put("timeout", timeout);
+
+ return this;
+ }
+
+ public TaskOptionsObject delay(int delay) {
+ options.put("delay", delay);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return options;
+ }
+}
View
14 client/src/main/java/io/iron/ironworker/client/builders/TaskProgressOptions.java
@@ -0,0 +1,14 @@
+package io.iron.ironworker.client.builders;
+
+public class TaskProgressOptions {
+ public static TaskProgressOptionsObject percent(int percent) {
+ return (new TaskProgressOptionsObject()).percent(percent);
+ }
+
+ public static TaskProgressOptionsObject msg(String msg) {
+ return (new TaskProgressOptionsObject()).msg(msg);
+ }
+
+ protected TaskProgressOptions() {
+ }
+}
View
28 client/src/main/java/io/iron/ironworker/client/builders/TaskProgressOptionsObject.java
@@ -0,0 +1,28 @@
+package io.iron.ironworker.client.builders;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TaskProgressOptionsObject {
+ private Map<String, Object> options;
+
+ public TaskProgressOptionsObject() {
+ options = new HashMap<String, Object>();
+ }
+
+ public TaskProgressOptionsObject percent(int percent) {
+ options.put("percent", percent);
+
+ return this;
+ }
+
+ public TaskProgressOptionsObject msg(String msg) {
+ options.put("msg", msg);
+
+ return this;
+ }
+
+ public Map<String, Object> create() {
+ return options;
+ }
+}
View
25 client/src/main/java/io/iron/ironworker/client/entities/BaseEntity.java
@@ -1,12 +1,33 @@
package io.iron.ironworker.client.entities;
+import com.google.gson.JsonObject;
import org.joda.time.format.ISODateTimeFormat;
import java.util.Date;
public class BaseEntity {
- public static Date parseDate(String date) {
- return ISODateTimeFormat.dateTimeNoMillis().parseDateTime(date).toDate();
+ public static String parseString(JsonObject o, String field, String def) {
+ return o.has(field) ? o.get(field).getAsString() : def;
+ }
+
+ public static String parseString(JsonObject o, String field) {
+ return parseString(o, field, null);
+ }
+
+ public static int parseInt(JsonObject o, String field, int def) {
+ return o.has(field) ? o.get(field).getAsInt() : def;
+ }
+
+ public static int parseInt(JsonObject o, String field) {
+ return parseInt(o, field, 0);
+ }
+
+ public static Date parseDate(JsonObject o, String field, Date def) {
+ return o.has(field) ? ISODateTimeFormat.dateTimeNoMillis().parseDateTime(o.get(field).getAsString()).toDate() : def;
+ }
+
+ public static Date parseDate(JsonObject o, String field) {
+ return parseDate(o, field, null);
}
protected BaseEntity() {
View
20 client/src/main/java/io/iron/ironworker/client/entities/CodeEntity.java
@@ -19,16 +19,16 @@
public static CodeEntity fromJsonObject(JsonObject o) {
CodeEntity c = new CodeEntity();
- c.id = o.get("id").getAsString();
- c.projectId = o.get("project_id").getAsString();
- c.name = o.get("name").getAsString();
- c.runtime = o.get("runtime").getAsString();
- c.revision = o.get("rev").getAsInt();
- c.latestHistoryId = o.get("latest_history_id").getAsString();
- c.latestChecksum = o.get("latest_checksum").getAsString();
- c.latestChange = parseDate(o.get("latest_change").getAsString());
- c.createdAt = parseDate(o.get("created_at").getAsString());
- c.updatedAt = parseDate(o.get("updated_at").getAsString());
+ c.id = parseString(o, "id");
+ c.projectId = parseString(o, "project_id");
+ c.name = parseString(o, "name");
+ c.runtime = parseString(o, "runtime");
+ c.revision = parseInt(o, "rev");
+ c.latestHistoryId = parseString(o, "latest_history_id");
+ c.latestChecksum = parseString(o, "latest_checksum");
+ c.latestChange = parseDate(o, "latest_change");
+ c.createdAt = parseDate(o, "created_at");
+ c.updatedAt = parseDate(o, "updated_at");
return c;
}
View
32 client/src/main/java/io/iron/ironworker/client/entities/CodeRevisionEntity.java
@@ -10,25 +10,25 @@
String projectId;
String name;
String runtime;
- String fileName;
+ String runner;
int revision;
Date createdAt;
Date updatedAt;
public static CodeRevisionEntity fromJsonObject(JsonObject o) {
- CodeRevisionEntity c = new CodeRevisionEntity();
-
- c.id = o.get("id").getAsString();
- c.codeId = o.get("code_id").getAsString();
- c.projectId = o.get("project_id").getAsString();
- c.name = o.get("name").getAsString();
- c.runtime = o.get("runtime").getAsString();
- c.fileName = o.get("file_name").getAsString();
- c.revision = o.get("rev").getAsInt();
- c.createdAt = parseDate(o.get("created_at").getAsString());
- c.updatedAt = parseDate(o.get("updated_at").getAsString());
-
- return c;
+ CodeRevisionEntity cr = new CodeRevisionEntity();
+
+ cr.id = parseString(o, "id");
+ cr.codeId = parseString(o, "code_id");
+ cr.projectId = parseString(o, "project_id");
+ cr.name = parseString(o, "name");
+ cr.runtime = parseString(o, "runtime");
+ cr.runner = parseString(o, "file_name");
+ cr.revision = parseInt(o, "rev");
+ cr.createdAt = parseDate(o, "created_at");
+ cr.updatedAt = parseDate(o, "updated_at");
+
+ return cr;
}
protected CodeRevisionEntity() {
@@ -54,8 +54,8 @@ public String getRuntime() {
return runtime;
}
- public String getFileName() {
- return fileName;
+ public String getRunner() {
+ return runner;
}
public int getRevision() {
View
108 client/src/main/java/io/iron/ironworker/client/entities/TaskEntity.java
@@ -0,0 +1,108 @@
+package io.iron.ironworker.client.entities;
+
+import com.google.gson.JsonObject;
+
+import java.util.Date;
+
+public class TaskEntity extends BaseEntity {
+ String id;
+ String projectId;
+ String codeId;
+ String codeName;
+ String status;
+ Date startTime;
+ Date endTime;
+ int duration;
+ int runTimes;
+ int timeout;
+ String payload;
+ int percent;
+ String msg;
+ Date createdAt;
+ Date updatedAt;
+
+ public static TaskEntity fromJsonObject(JsonObject o) {
+ TaskEntity t = new TaskEntity();
+
+ t.id = parseString(o, "id");
+ t.projectId = parseString(o, "project_id");
+ t.codeId = parseString(o, "code_id");
+ t.codeName = parseString(o, "code_name");
+ t.status = parseString(o, "status");
+ t.startTime = parseDate(o, "start_time");
+ t.endTime = parseDate(o, "end_time");
+ t.duration = parseInt(o, "duration");
+ t.runTimes = parseInt(o, "run_times");
+ t.timeout = parseInt(o, "timeout");
+ t.payload = parseString(o, "payload");
+ t.percent = parseInt(o, "percent");
+ t.msg = parseString(o, "msg");
+ t.createdAt = parseDate(o, "created_at");
+ t.updatedAt = parseDate(o, "updated_at");
+
+ return t;
+ }
+
+ protected TaskEntity() {
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public String getCodeId() {
+ return codeId;
+ }
+
+ public String getCodeName() {
+ return codeName;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public Date getStartTime() {
+ return startTime;
+ }
+
+ public Date getEndTime() {
+ return endTime;
+ }
+
+ public int getDuration() {
+ return duration;
+ }
+
+ public int getRunTimes() {
+ return runTimes;
+ }
+
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public String getPayload() {
+ return payload;
+ }
+
+ public int getPercent() {
+ return percent;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.