Create Endpoints to deploy DAS artifacts as Strings

Four new endpoints were created to deploy DAS artifacts. These apis will accept JSON payloads and convert them to Strings and will use those to deploy artifacts. These endpoints are different from the existing endpoints due to accepting different payloads and using different stubs to deploy.
3.x.x
Yohan Avishke 5 years ago
parent bed68289b5
commit 3dff9fef80

@ -44,6 +44,9 @@ public class APIUtil {
private static final String DEFAULT_CDMF_API_TAG = "device_management"; private static final String DEFAULT_CDMF_API_TAG = "device_management";
private static final String DEFAULT_AGENT_API_TAG = "device_agent"; private static final String DEFAULT_AGENT_API_TAG = "device_agent";
private static final String DEFAULT_CERT_API_TAG = "scep_management"; private static final String DEFAULT_CERT_API_TAG = "scep_management";
private static final String DEFAULT_ANALYTICS_ARTIFACT_TAG = "analytics_artifacts_management";
public static final String PERMISSION_PROPERTY_NAME = "name"; public static final String PERMISSION_PROPERTY_NAME = "name";
public static String getAuthenticatedUser() { public static String getAuthenticatedUser() {
@ -108,6 +111,7 @@ public class APIUtil {
allowedApisTags.add(DEFAULT_CDMF_API_TAG); allowedApisTags.add(DEFAULT_CDMF_API_TAG);
allowedApisTags.add(DEFAULT_CERT_API_TAG); allowedApisTags.add(DEFAULT_CERT_API_TAG);
allowedApisTags.add(DEFAULT_AGENT_API_TAG); allowedApisTags.add(DEFAULT_AGENT_API_TAG);
allowedApisTags.add(DEFAULT_ANALYTICS_ARTIFACT_TAG);
return allowedApisTags; return allowedApisTags;
} }

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
@ -23,10 +22,5 @@ package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
*/ */
public enum AttributeType { public enum AttributeType {
STRING, LONG, BOOL, INT, FLOAT, DOUBLE; STRING, LONG, BOOL, INT, FLOAT, DOUBLE;
@Override
public String toString() {
return super.toString().toLowerCase();
}
} }

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,62 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
/**
* Stream event attribute data
* Attributes : three lists for each attribute type
*/
public class EventAttributeLists {
@ApiModelProperty(value = "Meta attribute list")
private List<Attribute> metaAttributes;
@ApiModelProperty(value = "Correlation attribute list")
private List<Attribute> correlationAttributes;
@ApiModelProperty(value = "Payload attribute list")
private List<Attribute> payloadAttributes;
public List<Attribute> getMetaAttributes() {
return metaAttributes;
}
public void setMetaAttributes(
List<Attribute> metaAttributes) {
this.metaAttributes = metaAttributes;
}
public List<Attribute> getCorrelationAttributes() {
return correlationAttributes;
}
public void setCorrelationAttributes(
List<Attribute> correlationAttributes) {
this.correlationAttributes = correlationAttributes;
}
public List<Attribute> getPayloadAttributes() {
return payloadAttributes;
}
public void setPayloadAttributes(
List<Attribute> payloadAttributes) {
this.payloadAttributes = payloadAttributes;
}
}

@ -0,0 +1,34 @@
/*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
import io.swagger.annotations.ApiModelProperty;
public class EventPublisher {
@ApiModelProperty(value = "Publisher definition")
private String definition;
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
}

@ -0,0 +1,34 @@
/*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
import io.swagger.annotations.ApiModelProperty;
public class EventReceiver {
@ApiModelProperty(value = "Stream definition")
private String definition;
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
}

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,11 +14,14 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
import com.sun.istack.NotNull;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.NotEmpty;
import java.util.List;
/** /**
* Stream definition * Stream definition
@ -26,44 +29,86 @@ import io.swagger.annotations.ApiModelProperty;
*/ */
public class EventStream { public class EventStream {
@ApiModelProperty(value = "Stream name") @ApiModelProperty(value = "Stream name")
private String streamName; private String name;
@ApiModelProperty(value = "Stream version") @ApiModelProperty(value = "Stream version")
private String streamVersion; private String version;
@ApiModelProperty(value = "Stream definition") @ApiModelProperty(value = "Stream nickName")
private String streamDefinition; private String nickName;
@ApiModelProperty(value = "Stream property attribute lists") @ApiModelProperty(value = "Stream description")
private EventAttributeLists eventAttributeLists; private String description;
@ApiModelProperty(value = "Meta attribute list")
private List<Attribute> metaData;
@ApiModelProperty(value = "Correlation attribute list")
private List<Attribute> correlationData;
@ApiModelProperty(value = "Payload attribute list")
private List<Attribute> payloadData;
@ApiModelProperty(value = "Stream definition") @NotNull @NotEmpty
private String definition;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStreamName() { public List<Attribute> getMetaData() {
return streamName; return metaData;
} }
public void setStreamName(String streamName) { public void setMetaData(
this.streamName = streamName; List<Attribute> metaData) {
this.metaData = metaData;
} }
public String getStreamVersion() { public List<Attribute> getCorrelationData() {
return streamVersion; return correlationData;
} }
public void setStreamVersion(String streamVersion) { public void setCorrelationData(
this.streamVersion = streamVersion; List<Attribute> correlationData) {
this.correlationData = correlationData;
} }
public String getStreamDefinition() { public List<Attribute> getPayloadData() {
return streamDefinition; return payloadData;
} }
public void setStreamDefinition(String streamDefinition) { public void setPayloadData(
this.streamDefinition = streamDefinition; List<Attribute> payloadData) {
this.payloadData = payloadData;
} }
public EventAttributeLists getEventAttributeLists() { public String getDefinition() {
return eventAttributeLists; return definition;
} }
public void setEventAttributeLists( public void setDefinition(String definition) {
EventAttributeLists eventAttributeLists) { this.definition = definition;
this.eventAttributeLists = eventAttributeLists;
} }
} }

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
@ -22,27 +21,17 @@ import io.swagger.annotations.ApiModelProperty;
/** /**
* Execution plan definition including : * Execution plan definition including :
* Attributes : Name and Plan data. * Attributes : Plan data.
*/ */
public class SiddhiExecutionPlan { public class SiddhiExecutionPlan {
@ApiModelProperty(value = "Execution plan name") @ApiModelProperty(value = "Execution plan definition")
private String executionPlanName; private String definition;
@ApiModelProperty(value = "Execution plan")
private String executionPlanData;
public String getExecutionPlanName() {
return executionPlanName;
}
public void setExecutionPlanName(String executionPlanName) {
this.executionPlanName = executionPlanName;
}
public String getExecutionPlanData() { public String getDefinition() {
return executionPlanData; return definition;
} }
public void setExecutionPlanData(String executionPlanData) { public void setDefinition(String definition) {
this.executionPlanData = executionPlanData; this.definition = definition;
} }
} }

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,7 +14,6 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics; package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;

@ -18,19 +18,31 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.exception; package org.wso2.carbon.device.mgt.jaxrs.exception;
public class InvalidExecutionPlanException extends Exception{ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
private String errorMessage; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
public String getErrorMessage() { import javax.ws.rs.WebApplicationException;
return errorMessage; import javax.ws.rs.core.Response;
public class InvalidExecutionPlanException extends WebApplicationException {
private String message;
private static final long serialVersionUID = 7583096344745990515L;
public InvalidExecutionPlanException(ErrorResponse error) {
super(Response.status(Response.Status.NOT_FOUND).entity(error).build());
} }
public void setErrorMessage(String errorMessage) { public InvalidExecutionPlanException(ErrorDTO errorDTO) {
this.errorMessage = errorMessage; super(Response.status(Response.Status.NOT_FOUND)
.entity(errorDTO)
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
.build());
message = errorDTO.getDescription();
} }
public InvalidExecutionPlanException(String msg) { @Override
super(msg); public String getMessage() {
setErrorMessage(msg); return message;
} }
} }

@ -0,0 +1,454 @@
/*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.jaxrs.service.api;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventPublisher;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventReceiver;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "AnalyticsArtifactsManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/analytics/artifacts"),
})
}
),
tags = {
@Tag(name = "analytics_artifacts_management", description = "")
}
)
@Scopes(
scopes = {
@Scope(
name = "Create Event Stream Artifact",
description = "Create Event Stream Artifact",
key = "perm:analytics:artifacts:stream",
permissions = {"/device-mgt/analytics/artifacts/stream/add"}
),
@Scope(
name = "Create Event Receiver Artifact",
description = "Create Event Receiver Artifact",
key = "perm:analytics:artifacts:receiver",
permissions = {"/device-mgt/analytics/artifacts/receiver/add"}
),
@Scope(
name = "Create Event Publisher Artifact",
description = "Create Event Publisher Artifact",
key = "perm:analytics:artifacts:publisher",
permissions = {"/device-mgt/analytics/artifacts/publisher/add"}
),
@Scope(
name = "Create Siddhi Script Artifact",
description = "Create Siddhi Script Artifact",
key = "perm:analytics:artifacts:siddhi",
permissions = {"/device-mgt/analytics/artifacts/siddhi-script/add"}
)
}
)
@Path("/analytics/artifacts")
@Api(value = "Analytics Artifacts Management", description = "This API corresponds to services" +
" related to Analytics Artifacts management")
public interface AnalyticsArtifactsManagementService {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/stream/{id}")
@ApiOperation(
httpMethod = "POST",
value = "Create Event Stream Artifact as String",
notes = "Deploy a Json Stream Artifact in Analytics server.",
tags = "Analytics Artifacts Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:stream")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deployed the Stream Artifact.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message = "Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while deploying the " +
"Stream Artifact.",
response = ErrorResponse.class)
}
)
Response deployEventDefinitionAsString(@PathParam("id") String id,
@QueryParam("isEdited") boolean isEdited,
@Valid EventStream stream);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/stream")
@ApiOperation(
httpMethod = "POST",
value = "Create Event Stream Artifact as DTO",
notes = "Deploy a Json Stream Artifact in Analytics server.",
tags = "Analytics Artifacts Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:stream")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deployed the Stream Artifact.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message = "Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while deploying the " +
"Stream Artifact.",
response = ErrorResponse.class)
}
)
Response deployEventDefinitionAsDto(@Valid EventStream stream);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/receiver/{name}")
@ApiOperation(
httpMethod = "POST",
value = "Create Event Receiver Artifact as String",
notes = "Deploy a XML Event Receiver Artifact in Analytics server.",
tags = "Analytics Artifacts Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:receiver")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deployed the Receiver Artifact.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while deploying the " +
"Event Receiver Artifact.",
response = ErrorResponse.class)
}
)
Response deployEventReceiverAsString(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited,
@Valid EventReceiver receiver);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/receiver")
@ApiOperation(
httpMethod = "POST",
value = "Create Event Receiver Artifact as DTO",
notes = "Deploy a JSON Event Receiver Artifact in Analytics server.",
tags = "Analytics Artifacts Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:receiver")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deployed the Receiver Artifact.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while deploying the " +
"Event Receiver Artifact.",
response = ErrorResponse.class)
}
)
Response deployEventReceiverAsDto(@Valid Adapter receiver);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/publisher/{name}")
@ApiOperation(
httpMethod = "POST",
value = "Create Event Publisher Artifact as String",
notes = "Deploy a XML Event Publisher Artifact in Analytics server.",
tags = "Analytics Artifacts Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:publisher")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deployed the Publisher Artifact.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while deploying the " +
"Event Publisher Artifact.",
response = ErrorResponse.class)
}
)
Response deployEventPublisherAsString(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited,
@Valid EventPublisher publisher);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/publisher")
@ApiOperation(
httpMethod = "POST",
value = "Create Event Publisher Artifact as DTO",
notes = "Deploy a JSON Event Publisher Artifact in Analytics server.",
tags = "Analytics Artifacts Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:publisher")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deployed the Publisher Artifact.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while deploying the " +
"Event Publisher Artifact.",
response = ErrorResponse.class)
}
)
Response deployEventPublisherAsDto(@Valid Adapter publisher);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/siddhi-script/{name}")
@ApiOperation(
httpMethod = "POST",
value = "Create Siddhi Script Artifact as String",
notes = "Deploy a SiddhiQL Siddhi script Artifact in Analytics server.",
tags = "Analytics Artifacts Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:artifacts:siddhi")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deployed the Siddhi script Artifact.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while " +
"deploying the Siddhi script Artifact.",
response = ErrorResponse.class)
}
)
Response deploySiddhiExecutableScript(
@PathParam("name") String name, @QueryParam("isEdited") boolean isEdited,
@Valid SiddhiExecutionPlan plan);
}

@ -1,290 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "AnalyticsManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/analytics"),
})
}
),
tags = {
@Tag(name = "analytics_management", description = "")
}
)
@Scopes(
scopes = {
@Scope(
name = "Add Event stream",
description = "Add definition of a Event stream",
key = "perm:analytics:events",
permissions = {"/device-mgt/analytics/event/add"}
),
@Scope(
name = "Add Publisher",
description = "Add definition of a Publisher",
key = "perm:analytics:publisher",
permissions = {"/device-mgt/analytics/publisher/add"}
),
@Scope(
name = "Add Receiver",
description = "Add definition of a Receiver",
key = "perm:analytics:receiver",
permissions = {"/device-mgt/analytics/receiver/add"}
),
@Scope(
name = "Add Siddhi script",
description = "Add definition of a Siddhi script",
key = "perm:analytics:script",
permissions = {"/device-mgt/analytics/script/add"}
)
}
)
@Path("/analytics")
@Api(value = "Analytics Management", description = "This API corresponds to all tasks related analytics server")
@Consumes(MediaType.APPLICATION_JSON)
public interface AnalyticsManagementService {
@POST
@Path("/event")
@ApiOperation(
httpMethod = "POST",
value = "Adding the Event Type Definition",
notes = "Add the event definition to analytics.",
tags = "Analytics Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:events")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully added the event defintion.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while publishing the " +
"Event stream.",
response = ErrorResponse.class)
}
)
Response deployEventDefinition(@Valid EventStream stream);
@POST
@Path("/receiver")
@ApiOperation(
httpMethod = "POST",
value = "Adding an Event Receiver",
notes = "Add the receiver for an event",
tags = "Analytics Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:receiver")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully added the receiver.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while publishing the " +
"Event receiver.",
response = ErrorResponse.class)
}
)
Response deployEventReceiver(Adapter receiver);
@POST
@Path("/publisher")
@ApiOperation(
httpMethod = "POST",
value = "Adding an Event Publisher",
notes = "Add the publisher for an event",
tags = "Analytics Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:publisher")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully added the publisher.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while publishing the " +
"Event publisher.",
response = ErrorResponse.class)
}
)
Response deployEventPublisher(@Valid Adapter publisher);
@POST
@Path("/executable")
@ApiOperation(
httpMethod = "POST",
value = "Adding a Siddhi executable",
notes = "Add a Siddhi executable for a event",
tags = "Analytics Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:analytics:script")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully added the execution plan.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body."),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description =
"Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}
),
@ApiResponse(
code = 400,
message =
"Bad Request."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while " +
"publishing the Execution plan.",
response = ErrorResponse.class)
}
)
Response deploySiddhiExecutableScript(@Valid SiddhiExecutionPlan plan);
}

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -14,15 +14,9 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.impl; package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Stub;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Attribute;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterMappingConfiguration; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterMappingConfiguration;
@ -31,14 +25,15 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterConfiguration;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterProperty; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.AdapterProperty;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MessageFormat; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MessageFormat;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.SiddhiExecutionPlan;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventPublisher;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventReceiver;
import org.wso2.carbon.device.mgt.jaxrs.exception.ErrorDTO;
import org.wso2.carbon.device.mgt.jaxrs.exception.InvalidExecutionPlanException; import org.wso2.carbon.device.mgt.jaxrs.exception.InvalidExecutionPlanException;
import org.wso2.carbon.device.mgt.jaxrs.service.api.AnalyticsManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.AnalyticsArtifactsManagementService;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.Adapter;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeLists;
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventStream;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub;
import org.wso2.carbon.event.processor.stub.types.ExecutionPlanConfigurationDto;
import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub; import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub;
import org.wso2.carbon.event.publisher.stub.types.BasicOutputAdapterPropertyDto; import org.wso2.carbon.event.publisher.stub.types.BasicOutputAdapterPropertyDto;
import org.wso2.carbon.event.publisher.stub.types.EventPublisherConfigurationDto; import org.wso2.carbon.event.publisher.stub.types.EventPublisherConfigurationDto;
@ -52,71 +47,136 @@ import org.wso2.carbon.event.stream.stub.types.EventStreamDefinitionDto;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Stub;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.nio.charset.StandardCharsets;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.List; import java.util.List;
/** /**
* This class is used to create endpoints to serve the deployment of streams, adapters, siddhi * This class is used to create endpoints to serve the deployment of streams, publishers, receivers,
* execution plans to the DAS * siddhi scripts to the Analytics server as Artifacts
*/ */
@Path("/analytics") @Path("/analytics/artifacts")
public class AnalyticsManagementServiceImpl implements AnalyticsManagementService { public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifactsManagementService {
private static final Log log = LogFactory.getLog(AnalyticsManagementServiceImpl.class); private static final Log log = LogFactory.getLog(AnalyticsArtifactsManagementServiceImpl.class);
/** /**
* @param eventStream EventStream object with the properties of the stream * @param stream EventStream object with the properties of the stream
* @return A status code depending on the code result * @return A status code depending on the code result
* Function - Deploy a event stream * Function - Used to deploy stream as an artifact using a String
*/ */
@Override @Override
@POST @POST
@Path("/event") @Path("/stream/{id}")
public Response deployEventDefinition(@Valid EventStream eventStream) { public Response deployEventDefinitionAsString(@PathParam("id") String id,
@QueryParam("isEdited") boolean isEdited,
@Valid EventStream stream) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
try {
String streamDefinition = new String(stream.getDefinition().getBytes(), StandardCharsets.UTF_8);
eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
if (!isEdited) {
eventStreamAdminServiceStub.addEventStreamDefinitionAsString(streamDefinition);
} else {
// Find and edit stream
if (eventStreamAdminServiceStub.getStreamDetailsForStreamId(id) != null) {
eventStreamAdminServiceStub.editEventStreamDefinitionAsString(streamDefinition, id);
}
}
return Response.ok().build();
} catch (AxisFault e) {
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (RemoteException e) {
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (JWTClientException e) {
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (UserStoreException e) {
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} finally {
cleanup(eventStreamAdminServiceStub);
}
}
/**
* @param stream EventStream object with the properties of the stream
* @return A status code depending on the code result
* Function - Used to deploy stream as an artifact using a DTO
*/
@Override
@POST
@Path("/stream")
public Response deployEventDefinitionAsDto(@Valid EventStream stream) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
EventAttributeLists eventAttributes = eventStream.getEventAttributeLists();
// Categorize attributes to three lists depending on their type // Categorize attributes to three lists depending on their type
List<Attribute> eventMetaAttributes = eventAttributes.getMetaAttributes(); List<Attribute> metaData = stream.getMetaData();
List<Attribute> eventPayloadAttributes = eventAttributes.getPayloadAttributes(); List<Attribute> payloadData = stream.getPayloadData();
List<Attribute> eventCorrelationAttributes = eventAttributes.getCorrelationAttributes(); List<Attribute> correlationData = stream.getCorrelationData();
try { try {
/* Conditions /* Conditions
* - At least one list should always be not null * - At least one list should always be not null
*/ */
if (eventStream.getEventAttributeLists() == null || if (metaData == null && correlationData == null && payloadData == null) {
(eventMetaAttributes == null && eventCorrelationAttributes == null && log.error("Invalid payload: event attributes");
eventPayloadAttributes == null)) {
log.error("Invalid payload: eventAttributeLists");
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} else { } else {
String streamName = eventStream.getStreamName();
String streamVersion = eventStream.getStreamVersion();
String streamDefinition = eventStream.getStreamDefinition();
// Publish the event stream // Publish the event stream
publishStream(streamName, streamVersion, streamDefinition, eventMetaAttributes, publishStream(stream, metaData, correlationData, payloadData);
eventPayloadAttributes, eventCorrelationAttributes); return Response.ok().build();
try {
/*
* Create a new tenant and if that tenant is not the super tenant execute the publish
* function for the new tenant
*/
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
publishStream(streamName, streamVersion, streamDefinition, eventMetaAttributes,
eventPayloadAttributes, eventCorrelationAttributes);
} }
} finally { } catch (AxisFault e) {
// End the new tenant flow log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
PrivilegedCarbonContext.endTenantFlow(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (RemoteException e) {
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (JWTClientException e) {
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (UserStoreException e) {
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.ok().build(); }
/**
* @param name Receiver name
* @param isEdited If receiver is created or edited
* @param receiver Receiver object with the properties of the receiver
* @return A status code depending on the code result
* Function - Used to deploy receiver as an artifact using a String
*/
@Override
@POST
@Path("/receiver/{name}")
public Response deployEventReceiverAsString(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited,
@Valid EventReceiver receiver) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
EventReceiverAdminServiceStub eventReceiverAdminServiceStub;
try {
String receiverDefinition = receiver.getDefinition();
eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
if (!isEdited) {
eventReceiverAdminServiceStub.deployEventReceiverConfiguration(receiverDefinition);
} else {
eventReceiverAdminServiceStub.editActiveEventReceiverConfiguration(receiverDefinition, name);
} }
} catch (AxisFault e) { } catch (AxisFault e) {
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
@ -131,17 +191,18 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.ok().entity(name).build();
} }
/** /**
* @param receiver Receiver definition data * @param receiver Receiver object with the properties of the receiver
* @return a status code depending on the code execution * @return A status code depending on the code result
* * Function - Deploy a event receiver * Function - Used to deploy receiver as an artifact using a DTO
*/ */
@Override @Override
@POST @POST
@Path("/receiver") @Path("/receiver")
public Response deployEventReceiver(Adapter receiver) { public Response deployEventReceiverAsDto(@Valid Adapter receiver) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String receiverName = receiver.getAdapterName(); String receiverName = receiver.getAdapterName();
String adapterType = receiver.getAdapterType().toStringFormatted(); String adapterType = receiver.getAdapterType().toStringFormatted();
@ -173,34 +234,57 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
if ((customMapping && if ((customMapping &&
(inputMappingProperties == null && namespaceMappingProperties == null) && (inputMappingProperties == null && namespaceMappingProperties == null) &&
(correlationMappingProperties == null && payloadMappingProperties == null && (correlationMappingProperties == null && payloadMappingProperties == null &&
metaMappingProperties == null)) || metaMappingProperties == null)) || messageFormat == null) {
messageFormat == null) { String errMsg = "Invalid mapping payload";
log.error("Invalid mapping payload"); log.error(errMsg);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} }
String eventStreamWithVersion = receiver.getEventStreamWithVersion(); String eventStreamWithVersion = receiver.getEventStreamWithVersion();
publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties, publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties,
namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties, namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties,
metaMappingProperties, messageFormat, eventStreamWithVersion); metaMappingProperties, messageFormat, eventStreamWithVersion);
try { return Response.ok().build();
/* } catch (AxisFault e) {
* Create a new tenant and if that tenant is not the super tenant execute the publish log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
* function for the new tenant return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
*/ } catch (RemoteException e) {
PrivilegedCarbonContext.startTenantFlow(); log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); } catch (JWTClientException e) {
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties, return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties, } catch (UserStoreException e) {
metaMappingProperties, messageFormat, eventStreamWithVersion); log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
} finally {
// End the new tenant flow
PrivilegedCarbonContext.endTenantFlow();
} }
return Response.ok().build();
/**
* @param name Publisher name
* @param isEdited If receiver is created or edited
* @param publisher Publisher object with the properties of the publisher
* @return A status code depending on the code result
* Function - Used to deploy publisher as an artifact using a String
*/
@Override
@POST
@Path("/publisher/{name}")
public Response deployEventPublisherAsString(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited,
@Valid EventPublisher publisher) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
EventPublisherAdminServiceStub eventPublisherAdminServiceStub;
try {
String publisherDefinition = publisher.getDefinition();
eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub();
if (!isEdited) {
eventPublisherAdminServiceStub.deployEventPublisherConfiguration(publisherDefinition);
} else {
eventPublisherAdminServiceStub.editActiveEventPublisherConfiguration(publisherDefinition, name);
}
} catch (AxisFault e) { } catch (AxisFault e) {
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -214,16 +298,18 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.ok().entity(publisher).build();
} }
/** /**
* @param publisher Publisher definition * @param publisher Publisher object with the properties of the publisher
* @return a status code depending on the code execution * @return A status code depending on the code result
* Function - Used to deploy publisher as an artifact using a DTO
*/ */
@Override @Override
@POST @POST
@Path("/publisher") @Path("/publisher")
public Response deployEventPublisher(@Valid Adapter publisher) { public Response deployEventPublisherAsDto(@Valid Adapter publisher) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String publisherName = publisher.getAdapterName(); String publisherName = publisher.getAdapterName();
String adapterType = publisher.getAdapterType().toStringFormatted(); String adapterType = publisher.getAdapterType().toStringFormatted();
@ -254,10 +340,10 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
if ((customMapping && if ((customMapping &&
(inputMappingProperties == null && inputMappingString == null) && (inputMappingProperties == null && inputMappingString == null) &&
(correlationMappingProperties == null && payloadMappingProperties == null && (correlationMappingProperties == null && payloadMappingProperties == null &&
metaMappingProperties == null)) || metaMappingProperties == null)) || messageFormat == null) {
messageFormat == null) { String errMsg = "Invalid mapping payload";
log.error("Invalid mapping payload"); log.error(errMsg);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
} }
String eventStreamWithVersion = publisher.getEventStreamWithVersion(); String eventStreamWithVersion = publisher.getEventStreamWithVersion();
@ -265,24 +351,6 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
, inputMappingString, inputMappingProperties, correlationMappingProperties , inputMappingString, inputMappingProperties, correlationMappingProperties
, payloadMappingProperties, metaMappingProperties, messageFormat , payloadMappingProperties, metaMappingProperties, messageFormat
, eventStreamWithVersion); , eventStreamWithVersion);
try {
/*
* Create a new tenant and if that tenant is not the super tenant execute the publish
* function for the new tenant
*/
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
publishPublisher(publisherName, adapterType, adapterProperties, customMapping
, inputMappingString, inputMappingProperties, correlationMappingProperties
, payloadMappingProperties, metaMappingProperties, messageFormat
, eventStreamWithVersion);
}
} finally {
// End the new tenant flow
PrivilegedCarbonContext.endTenantFlow();
}
return Response.ok().build(); return Response.ok().build();
} catch (AxisFault e) { } catch (AxisFault e) {
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
@ -300,33 +368,21 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
} }
/** /**
* @param executionPlan Siddhi execution plan definition * @param name Siddhi plan name
* @param isEdited If receiver is created or edited
* @param plan Siddhi plan definition
* @return a status code depending on the code execution * @return a status code depending on the code execution
* Function - Used to deploy Siddhi script as an artifact using a String
*/ */
@Override @Override
@POST @POST
@Path("/executable") @Path("/siddhi-script/{name}")
public Response deploySiddhiExecutableScript(@Valid SiddhiExecutionPlan executionPlan) { public Response deploySiddhiExecutableScript(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited,
@Valid SiddhiExecutionPlan plan) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
publishSiddhiExecutionPlan(executionPlan.getExecutionPlanName(), publishSiddhiExecutionPlan(name, isEdited, plan.getDefinition());
executionPlan.getExecutionPlanData());
try {
/*
* Create a new tenant and if that tenant is not the super tenant execute the publish
* function for the new tenant
*/
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
publishSiddhiExecutionPlan(executionPlan.getExecutionPlanName(),
executionPlan.getExecutionPlanData());
}
} finally {
// End the new tenant flow
PrivilegedCarbonContext.endTenantFlow();
}
return Response.ok().build(); return Response.ok().build();
} catch (AxisFault e) { } catch (AxisFault e) {
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e); log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
@ -334,45 +390,42 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
} catch (RemoteException e) { } catch (RemoteException e) {
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e); log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (InvalidExecutionPlanException e) {
log.error("Invalid Execution plan: " + tenantDomain, e);
return e.getResponse();
} catch (JWTClientException e) { } catch (JWTClientException e) {
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e); log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e); log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (InvalidExecutionPlanException e) {
log.error("Invalid Execution plan: " + tenantDomain, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
} }
/** /**
* @param streamName Name of the stream * @param stream Stream definition
* @param streamVersion Version of the stream * @param metaData Meta attributes of the stream
* @param streamDefinition Definition of the stream * @param correlationData Correlation attributes of the stream
* @param eventMetaAttributes Meta attributes of the stream * @param payloadData Payload attributes of the stream
* @param eventPayloadAttributes Payload attributes of the stream
* @param eventCorrelationAttributes Correlation attributes of the stream
* @throws RemoteException exception that may occur during a remote method call * @throws RemoteException exception that may occur during a remote method call
* @throws UserStoreException exception that may occur during JWT token generation * @throws UserStoreException exception that may occur during JWT token generation
* @throws JWTClientException exception that may occur during connecting to client store * @throws JWTClientException exception that may occur during connecting to client store
*/ */
private void publishStream(String streamName, String streamVersion, String streamDefinition, private void publishStream(EventStream stream, List<Attribute> metaData,
List<Attribute> eventMetaAttributes, List<Attribute> correlationData, List<Attribute> payloadData)
List<Attribute> eventPayloadAttributes,
List<Attribute> eventCorrelationAttributes)
throws RemoteException, UserStoreException, JWTClientException { throws RemoteException, UserStoreException, JWTClientException {
EventStreamAdminServiceStub eventStreamAdminServiceStub = EventStreamAdminServiceStub eventStreamAdminServiceStub =
DeviceMgtAPIUtils.getEventStreamAdminServiceStub(); DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
try { try {
EventStreamDefinitionDto eventStreamDefinitionDto = new EventStreamDefinitionDto(); EventStreamDefinitionDto eventStreamDefinitionDto = new EventStreamDefinitionDto();
eventStreamDefinitionDto.setName(streamName); eventStreamDefinitionDto.setName(stream.getName());
eventStreamDefinitionDto.setVersion(streamVersion); eventStreamDefinitionDto.setVersion(stream.getVersion());
eventStreamDefinitionDto.setDescription(streamDefinition); eventStreamDefinitionDto.setNickName(stream.getNickName());
eventStreamDefinitionDto.setMetaData(addEventAttributesToDto(eventMetaAttributes)); eventStreamDefinitionDto.setDescription(stream.getDescription());
eventStreamDefinitionDto.setPayloadData(addEventAttributesToDto(eventPayloadAttributes)); eventStreamDefinitionDto.setMetaData(addEventAttributesToDto(metaData));
eventStreamDefinitionDto.setCorrelationData(addEventAttributesToDto(eventCorrelationAttributes)); eventStreamDefinitionDto.setPayloadData(addEventAttributesToDto(payloadData));
String streamId = streamName + ":" + streamVersion; eventStreamDefinitionDto.setCorrelationData(addEventAttributesToDto(correlationData));
String streamId = stream.getName() + ":" + stream.getVersion();
if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) != null) { if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) != null) {
eventStreamAdminServiceStub.editEventStreamDefinitionAsDto(eventStreamDefinitionDto, streamId); eventStreamAdminServiceStub.editEventStreamDefinitionAsDto(eventStreamDefinitionDto, streamId);
} else { } else {
@ -558,48 +611,35 @@ public class AnalyticsManagementServiceImpl implements AnalyticsManagementServic
} }
/** /**
* @param executionPlanName Siddhi execution plan name * @param name plan name
* @param executionPlanData Siddhi execution plan * @param isEdited is plan edited
* @param plan plan data
* @throws RemoteException exception that may occur during a remote method call * @throws RemoteException exception that may occur during a remote method call
* @throws UserStoreException exception that may occur during JWT token generation * @throws UserStoreException exception that may occur during JWT token generation
* @throws JWTClientException exception that may occur during connecting to client store * @throws JWTClientException exception that may occur during connecting to client store
* @throws InvalidExecutionPlanException exception that may occur if execution plan validation fails * @throws InvalidExecutionPlanException exception that may occur if execution plan validation fails
*/ */
private void publishSiddhiExecutionPlan(String executionPlanName, String executionPlanData) private void publishSiddhiExecutionPlan(String name, boolean isEdited,
String plan)
throws RemoteException, UserStoreException, JWTClientException, throws RemoteException, UserStoreException, JWTClientException,
InvalidExecutionPlanException { InvalidExecutionPlanException {
EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null; EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null;
// Flag to check the existence of a plan
boolean isAvailable = false;
try { try {
eventProcessorAdminServiceStub = DeviceMgtAPIUtils.getEventProcessorAdminServiceStub(); eventProcessorAdminServiceStub = DeviceMgtAPIUtils.getEventProcessorAdminServiceStub();
// Validate the plan code // Validate the plan code
String validationResponse = eventProcessorAdminServiceStub.validateExecutionPlan(executionPlanData); String validationResponse = eventProcessorAdminServiceStub.validateExecutionPlan(plan);
if (validationResponse.equals("success")) { if (validationResponse.equals("success")) {
String activeExecutionPlanName = null; if (!isEdited) {
// Get active plans
ExecutionPlanConfigurationDto[] allActiveExecutionPlanConfigs = eventProcessorAdminServiceStub.getAllActiveExecutionPlanConfigurations();
if (allActiveExecutionPlanConfigs != null) {
for (ExecutionPlanConfigurationDto activeExecutionPlanConfig : allActiveExecutionPlanConfigs) {
activeExecutionPlanName = activeExecutionPlanConfig.getName();
if (activeExecutionPlanName.equals(executionPlanName)) {
isAvailable = true;
}
}
}
// Edit existing plan
if (isAvailable) {
eventProcessorAdminServiceStub.editActiveExecutionPlan(executionPlanData,
executionPlanName);
}
// Create a new plan // Create a new plan
else { eventProcessorAdminServiceStub.deployExecutionPlan(plan);
eventProcessorAdminServiceStub.deployExecutionPlan(executionPlanData); } else {
// Edit plan
eventProcessorAdminServiceStub.editActiveExecutionPlan(plan, name);
} }
} else { } else {
String errMsg = "Execution plan validation failed: " + validationResponse; ErrorDTO errorDTO = new ErrorDTO();
log.error(errMsg); errorDTO.setMessage(validationResponse);
throw new InvalidExecutionPlanException(errMsg); throw new InvalidExecutionPlanException(errorDTO);
} }
} finally { } finally {
cleanup(eventProcessorAdminServiceStub); cleanup(eventProcessorAdminServiceStub);

@ -639,16 +639,8 @@ public class DeviceMgtAPIUtils {
return eventStreamPersistenceAdminServiceStub; return eventStreamPersistenceAdminServiceStub;
} }
/**
*
* @return
* @throws AxisFault
* @throws UserStoreException
* @throws JWTClientException
*/
public static EventProcessorAdminServiceStub getEventProcessorAdminServiceStub() public static EventProcessorAdminServiceStub getEventProcessorAdminServiceStub()
throws AxisFault, UserStoreException, JWTClientException { throws AxisFault, UserStoreException, JWTClientException {
// Send alert to event-processing
EventProcessorAdminServiceStub eventProcessorAdminServiceStub = new EventProcessorAdminServiceStub( EventProcessorAdminServiceStub eventProcessorAdminServiceStub = new EventProcessorAdminServiceStub(
Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_PROCESSOR_CONTEXT)); Utils.replaceSystemProperty(DAS_ADMIN_SERVICE_EP + EVENT_PROCESSOR_CONTEXT));
Options eventProcessorOption = eventProcessorAdminServiceStub._getServiceClient().getOptions(); Options eventProcessorOption = eventProcessorAdminServiceStub._getServiceClient().getOptions();

@ -46,7 +46,7 @@
<ref bean="deviceEventManagementService"/> <ref bean="deviceEventManagementService"/>
<ref bean="deviceAgentService"/> <ref bean="deviceAgentService"/>
<ref bean="swaggerResource"/> <ref bean="swaggerResource"/>
<ref bean="analyticsManagementService"/> <ref bean="analyticsArtifactsManagementService"/>
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
<ref bean="jsonProvider"/> <ref bean="jsonProvider"/>
@ -94,7 +94,7 @@
<bean id="deviceEventManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceEventManagementServiceImpl"/> <bean id="deviceEventManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceEventManagementServiceImpl"/>
<bean id="deviceAgentService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceAgentServiceImpl"/> <bean id="deviceAgentService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceAgentServiceImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/>
<bean id="analyticsManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.AnalyticsManagementServiceImpl"/> <bean id="analyticsArtifactsManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.AnalyticsArtifactsManagementServiceImpl"/>
<!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>--> <!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>-->
<cxf:bus> <cxf:bus>

Loading…
Cancel
Save