Search in sources :

Example 1 with ApiServicesManagerException

use of com.bluenimble.platform.api.ApiServicesManagerException in project serverless by bluenimble.

the class DefaultApiServicesManager method stopService.

private void stopService(ApiService service, ApiContext context, boolean saveStatus) throws ApiServicesManagerException {
    ApiServiceImpl sImpl = (ApiServiceImpl) service;
    // call spi onStop
    boolean newContext = context == null;
    try {
        if (newContext) {
            context = new DefaultApiContext();
        }
        service.getSpi().onStop(api, service, context);
    } catch (ApiManagementException ex) {
        throw new ApiServicesManagerException(ex.getMessage(), ex);
    } finally {
        if (newContext) {
            context.recycle();
        }
    }
    // attach api
    sImpl.dettachSpi();
    // set service status
    sImpl.setStatus(ApiStatus.Stopped, saveStatus);
}
Also used : ApiServicesManagerException(com.bluenimble.platform.api.ApiServicesManagerException) ApiManagementException(com.bluenimble.platform.api.ApiManagementException)

Example 2 with ApiServicesManagerException

use of com.bluenimble.platform.api.ApiServicesManagerException in project serverless by bluenimble.

the class DefaultApiServicesManager method start.

@Override
public void start(ApiVerb verb, String endpoint) throws ApiServicesManagerException {
    ApiService service = get(verb, endpoint);
    if (service == null) {
        throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
    }
    if (!service.status().equals(ApiStatus.Stopped)) {
        throw new ApiServicesManagerException("unnable to start service [" + verb + " " + endpoint + "]. Status=" + service.status());
    }
    startService(service, null, false);
}
Also used : ApiServicesManagerException(com.bluenimble.platform.api.ApiServicesManagerException) ApiService(com.bluenimble.platform.api.ApiService)

Example 3 with ApiServicesManagerException

use of com.bluenimble.platform.api.ApiServicesManagerException 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 4 with ApiServicesManagerException

use of com.bluenimble.platform.api.ApiServicesManagerException in project serverless by bluenimble.

the class DefaultApiServicesManager method stop.

@Override
public void stop(ApiVerb verb, String endpoint) throws ApiServicesManagerException {
    ApiService service = get(verb, endpoint);
    if (service == null) {
        throw new ApiServicesManagerException("service [" + verb + " " + endpoint + "] not found");
    }
    if (!service.status().equals(ApiStatus.Running) || !service.status().equals(ApiStatus.Paused)) {
        throw new ApiServicesManagerException("unnable to stop service [" + verb + " " + endpoint + "]. Status=" + service.status());
    }
    stopService(service, null, true);
}
Also used : ApiServicesManagerException(com.bluenimble.platform.api.ApiServicesManagerException) ApiService(com.bluenimble.platform.api.ApiService)

Example 5 with ApiServicesManagerException

use of com.bluenimble.platform.api.ApiServicesManagerException in project serverless by bluenimble.

the class DefaultApiServicesManager method load.

@Override
public void load(Api api) throws ApiServicesManagerException {
    this.api = (ApiImpl) api;
    ApiResourcesManager rmgr = api.getResourcesManager();
    try {
        load(rmgr, rmgr.get(new String[] { ConfigKeys.Folders.Services }));
    } catch (ApiResourcesManagerException e) {
        throw new ApiServicesManagerException(e.getMessage(), e);
    }
}
Also used : ApiServicesManagerException(com.bluenimble.platform.api.ApiServicesManagerException) ApiResourcesManager(com.bluenimble.platform.api.ApiResourcesManager) ApiResourcesManagerException(com.bluenimble.platform.api.ApiResourcesManagerException)

Aggregations

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