Search in sources :

Example 1 with ApiServiceSet

use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.

the class DefaultApiServicesManager method put.

@Override
public ApiService put(ApiResource resource) throws ApiServicesManagerException {
    Exception failure = null;
    JsonObject source = null;
    InputStream stream = null;
    try {
        stream = resource.toInput();
        source = Json.load(stream);
    } catch (Exception ex) {
        failure = ex;
        ;
    } finally {
        IOUtils.closeQuietly(stream);
    }
    if (failure != null) {
        source = (JsonObject) new JsonObject().set(ApiService.Spec.Status, ApiStatus.Failed.name()).set(ApiService.Spec.Endpoint, resource.path());
    }
    ApiServiceImpl service = new ApiServiceImpl(resource, source, api);
    if (failure != null) {
        service.failed(failure);
    }
    if (failure == null) {
        if (exists(service.getVerb(), service.getEndpoint())) {
            delete(service.getVerb(), service.getEndpoint());
        }
    }
    ApiServiceSet set = services.get(service.getVerb());
    if (set == null) {
        set = new ApiServiceSet();
        services.put(service.getVerb(), set);
    }
    set.add(service);
    return service;
}
Also used : InputStream(java.io.InputStream) JsonObject(com.bluenimble.platform.json.JsonObject) ApiServiceSet(com.bluenimble.platform.server.impls.fs.ApiServiceSet) ApiManagementException(com.bluenimble.platform.api.ApiManagementException) ApiServicesManagerException(com.bluenimble.platform.api.ApiServicesManagerException) ApiResourcesManagerException(com.bluenimble.platform.api.ApiResourcesManagerException)

Example 2 with ApiServiceSet

use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.

the class DefaultApiServicesManager method get.

@Override
public ApiService get(ApiVerb verb, String endpoint) {
    ApiServiceSet set = services.get(verb);
    if (set == null) {
        return null;
    }
    ApiService service = set.get(resolveEndpoint(endpoint));
    if (service == null) {
        return null;
    }
    return service;
}
Also used : ApiService(com.bluenimble.platform.api.ApiService) ApiServiceSet(com.bluenimble.platform.server.impls.fs.ApiServiceSet)

Example 3 with ApiServiceSet

use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.

the class DefaultApiServicesManager method delete.

@Override
public void delete(ApiVerb verb, String endpoint) throws ApiServicesManagerException {
    ApiServiceSet set = services.get(verb);
    if (set == null) {
        throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
    }
    ApiService service = set.get(endpoint);
    if (service == null) {
        throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
    }
    if (!ApiStatus.Failed.equals(service.status()) && !ApiStatus.Stopped.equals(service.status())) {
        throw new ApiServicesManagerException("can't delete service [" + verb + " " + endpoint + "]. Status=" + service.status());
    }
    set.remove(endpoint);
}
Also used : ApiServicesManagerException(com.bluenimble.platform.api.ApiServicesManagerException) ApiService(com.bluenimble.platform.api.ApiService) ApiServiceSet(com.bluenimble.platform.server.impls.fs.ApiServiceSet)

Example 4 with ApiServiceSet

use of com.bluenimble.platform.server.impls.fs.ApiServiceSet in project serverless by bluenimble.

the class DefaultApiServicesManager method list.

@Override
public void list(Selector selector) {
    if (selector == null || services.isEmpty()) {
        return;
    }
    Iterator<ApiVerb> verbs = services.keySet().iterator();
    while (verbs.hasNext()) {
        ApiVerb verb = verbs.next();
        ApiServiceSet set = services.get(verb);
        Iterator<String> endpoints = set.endpoints();
        if (endpoints == null) {
            continue;
        }
        while (endpoints.hasNext()) {
            boolean cancel = selector.select(set.get(endpoints.next()));
            if (cancel) {
                return;
            }
        }
    }
}
Also used : ApiServiceSet(com.bluenimble.platform.server.impls.fs.ApiServiceSet) ApiVerb(com.bluenimble.platform.api.ApiVerb)

Aggregations

ApiServiceSet (com.bluenimble.platform.server.impls.fs.ApiServiceSet)4 ApiService (com.bluenimble.platform.api.ApiService)2 ApiServicesManagerException (com.bluenimble.platform.api.ApiServicesManagerException)2 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)1 ApiResourcesManagerException (com.bluenimble.platform.api.ApiResourcesManagerException)1 ApiVerb (com.bluenimble.platform.api.ApiVerb)1 JsonObject (com.bluenimble.platform.json.JsonObject)1 InputStream (java.io.InputStream)1