Search in sources :

Example 1 with Describe

use of com.bluenimble.platform.api.impls.ApiSpaceImpl.Describe in project serverless by bluenimble.

the class DefaultCodeExecutor method describe.

@Override
public JsonObject describe() {
    if (service == null) {
        return null;
    }
    JsonObject oThreads = new JsonObject();
    Thread[] threads = listThreads();
    if (threads == null) {
        return null;
    }
    for (Thread t : threads) {
        if (t == null) {
            continue;
        }
        String status = t.getState().name();
        if (State.WAITING.equals(t.getState())) {
            status = StateAvailable;
        }
        JsonObject oth = (JsonObject) new JsonObject().set(Describe.Worker.Id, t.getId()).set(Describe.Worker.Name, t.getName()).set(Describe.Worker.Status, status);
        if (t instanceof SpaceThread) {
            SpaceThread st = (SpaceThread) t;
            ApiRequest request = st.getRequest();
            if (request != null) {
                JsonObject oRequest = new JsonObject();
                oRequest.set(ApiRequest.Fields.Id, request.getId());
                oRequest.set(ApiRequest.Fields.Verb, request.getVerb().name());
                oRequest.set(ApiRequest.Fields.Endpoint, request.getEndpoint());
                oRequest.set(ApiRequest.Fields.Timestamp, Lang.toUTC(request.getTimestamp()));
                oth.set(Describe.Worker.request.class.getSimpleName(), oRequest);
                if (request.getService() != null) {
                    JsonObject oService = new JsonObject();
                    String script = Json.getString(request.getService().getRuntime(), Api.Spec.Runtime.Function);
                    oService.set(Api.Spec.Runtime.Function, script);
                    if (script == null) {
                        oService.set(Api.Spec.Runtime.Function, request.getService().getSpi().getClass().getSimpleName());
                    }
                    oService.set(ApiService.Spec.Endpoint, request.getService().getEndpoint());
                    oth.set(Describe.Worker.Service, oService);
                }
            }
        }
        oThreads.set(t.getName(), oth);
    }
    return oThreads;
}
Also used : Describe(com.bluenimble.platform.api.impls.ApiSpaceImpl.Describe) JsonObject(com.bluenimble.platform.json.JsonObject) ApiRequest(com.bluenimble.platform.api.ApiRequest)

Aggregations

ApiRequest (com.bluenimble.platform.api.ApiRequest)1 Describe (com.bluenimble.platform.api.impls.ApiSpaceImpl.Describe)1 JsonObject (com.bluenimble.platform.json.JsonObject)1