Search in sources :

Example 1 with ApiResponseMessage

use of org.wso2.siddhi.service.api.ApiResponseMessage in project siddhi by wso2.

the class SiddhiApiServiceImpl method siddhiArtifactUndeploySiddhiAppGet.

@Override
public Response siddhiArtifactUndeploySiddhiAppGet(String siddhiAppName) throws NotFoundException {
    String jsonString = new Gson().toString();
    if (siddhiAppName != null) {
        if (siddhiAppRunTimeMap.containsKey(siddhiAppName)) {
            siddhiAppRunTimeMap.remove(siddhiAppName);
            siddhiAppConfigurationMap.remove(siddhiAppName);
            siddhiAppSpecificInputHandlerMap.remove(siddhiAppName);
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.OK, "Siddhi app removed successfully"));
        } else {
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "There is no siddhi app exist " + "with provided name : " + siddhiAppName));
        }
    } else {
        jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "nvalid Request"));
    }
    return Response.ok().entity(jsonString).build();
}
Also used : ApiResponseMessage(org.wso2.siddhi.service.api.ApiResponseMessage) Gson(com.google.gson.Gson)

Example 2 with ApiResponseMessage

use of org.wso2.siddhi.service.api.ApiResponseMessage in project siddhi by wso2.

the class SiddhiApiServiceImpl method siddhiArtifactDeployPost.

@Override
public Response siddhiArtifactDeployPost(String siddhiApp) throws NotFoundException {
    log.info("SiddhiApp = " + siddhiApp);
    String jsonString = new Gson().toString();
    try {
        SiddhiApp parsedSiddhiApp = SiddhiCompiler.parse(siddhiApp);
        String siddhiAppName = AnnotationHelper.getAnnotationElement(SiddhiServiceConstants.ANNOTATION_NAME_NAME, null, parsedSiddhiApp.getAnnotations()).getValue();
        if (!siddhiAppRunTimeMap.containsKey(siddhiApp)) {
            SiddhiAppConfiguration siddhiAppConfiguration = new SiddhiAppConfiguration();
            siddhiAppConfiguration.setName(siddhiAppName);
            siddhiAppConfigurationMap.put(siddhiAppName, siddhiAppConfiguration);
            SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
            if (siddhiAppRuntime != null) {
                Set<String> streamNames = siddhiAppRuntime.getStreamDefinitionMap().keySet();
                Map<String, InputHandler> inputHandlerMap = new ConcurrentHashMap<>(streamNames.size());
                for (String streamName : streamNames) {
                    inputHandlerMap.put(streamName, siddhiAppRuntime.getInputHandler(streamName));
                }
                siddhiAppSpecificInputHandlerMap.put(siddhiAppName, inputHandlerMap);
                siddhiAppRunTimeMap.put(siddhiAppName, siddhiAppRuntime);
                siddhiAppRuntime.start();
                jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.OK, "Siddhi app is deployed " + "and runtime is created"));
            }
        } else {
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "There is a Siddhi app already " + "exists with same name"));
        }
    } catch (Exception e) {
        jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, e.getMessage()));
    }
    return Response.ok().entity(jsonString).build();
}
Also used : ApiResponseMessage(org.wso2.siddhi.service.api.ApiResponseMessage) InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) Gson(com.google.gson.Gson) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiAppConfiguration(org.wso2.siddhi.service.util.SiddhiAppConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NotFoundException(org.wso2.siddhi.service.api.NotFoundException)

Aggregations

Gson (com.google.gson.Gson)2 ApiResponseMessage (org.wso2.siddhi.service.api.ApiResponseMessage)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)1 NotFoundException (org.wso2.siddhi.service.api.NotFoundException)1 SiddhiAppConfiguration (org.wso2.siddhi.service.util.SiddhiAppConfiguration)1