Search in sources :

Example 1 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException 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 NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException 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)

Example 3 with NotFoundException

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

the class SiddhiApiTestCase method testDeployAndUndeploy.

@Test
public /**
 * Check deploy and undeploy functionality
 */
void testDeployAndUndeploy() throws NotFoundException {
    SiddhiApiServiceImpl apiService = new SiddhiApiServiceImpl();
    String siddhiApp = "@app:name('filterTest1') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select symbol, price " + "insert into outputStream;" + "" + "@info(name = 'query2') " + "from outputStream[70 > price] " + "select symbol, price " + "insert into outputStream2 ;";
    Response response = apiService.siddhiArtifactDeployPost(siddhiApp);
    Assert.assertEquals(response.getStatus(), 200, "HTTP 200 should be returned");
    Assert.assertTrue(response.getEntity().toString().contains("Siddhi app is deployed and runtime is created"), "Siddhi App creation message should be returned");
    Response undeployResponse = apiService.siddhiArtifactUndeploySiddhiAppGet("filterTest1");
    Assert.assertEquals(undeployResponse.getStatus(), 200, "HTTP 200 should be returned");
    Assert.assertTrue(undeployResponse.getEntity().toString().contains("Siddhi app removed successfully"), "Siddhi App removed message should be returned");
}
Also used : Response(javax.ws.rs.core.Response) SiddhiApiServiceImpl(org.wso2.siddhi.service.impl.SiddhiApiServiceImpl) Test(org.testng.annotations.Test)

Example 4 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdPut.

/**
 * Updates/adds a new Application throttle policy to the system
 *
 * @param id          Uuid of the policy.
 * @param body              DTO object including the Policy meta information
 * @param ifMatch           If-Match header value
 * @param ifUnmodifiedSince If-Unmodified-Since header value
 * @param request           msf4j request object
 * @return Response object  response object with the updated application throttle policy resource
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingApplicationIdPut(String id, ApplicationThrottlePolicyDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.application;
    if (log.isDebugEnabled()) {
        log.info("Received Application Policy PUT request " + body + " with tierLevel = " + tierLevel);
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        ApplicationPolicy applicationPolicy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(body);
        applicationPolicy.setUuid(id);
        apiMgtAdminService.updateApplicationPolicy(applicationPolicy);
        return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(apiMgtAdminService.getApplicationPolicyByUuid(id))).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while updating Application Policy. policy uuid: " + id;
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Example 5 with NotFoundException

use of org.wso2.siddhi.service.api.NotFoundException in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingCustomGet.

/**
 * Retrieves all custom policies.
 *
 * @param ifNoneMatch     If-None-Match header value
 * @param ifModifiedSince If-Modified-Since header value
 * @param request         msf4j request object
 * @return All matched Global Throttle policies to the given request
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingCustomGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    if (log.isDebugEnabled()) {
        log.debug("Received Custom Policy GET request.");
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        List<CustomPolicy> policies = apiMgtAdminService.getCustomRules();
        CustomRuleListDTO customRuleListDTO = CustomPolicyMappingUtil.fromCustomPolicyArrayToListDTO(policies);
        return Response.ok().entity(customRuleListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while retrieving custom policies";
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)171 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)142 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)120 HashMap (java.util.HashMap)117 Response (javax.ws.rs.core.Response)106 Test (org.junit.Test)100 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)99 Request (org.wso2.msf4j.Request)75 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)48 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)44 ArrayList (java.util.ArrayList)35 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)31 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)29 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)25 Map (java.util.Map)24 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)23 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)20 Application (org.wso2.carbon.apimgt.core.models.Application)19 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)18 CharonException (org.wso2.charon3.core.exceptions.CharonException)18