|
|
@ -18,6 +18,7 @@
|
|
|
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|
|
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
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;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MappingProperty;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.MappingProperty;
|
|
|
@ -25,8 +26,7 @@ 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.exception.BadRequestException;
|
|
|
|
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.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.AnalyticsArtifactsManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.AnalyticsArtifactsManagementService;
|
|
|
@ -58,7 +58,6 @@ import javax.ws.rs.Path;
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
@ -67,14 +66,10 @@ import java.util.List;
|
|
|
|
* siddhi scripts to the Analytics server as Artifacts
|
|
|
|
* siddhi scripts to the Analytics server as Artifacts
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Path("/analytics/artifacts")
|
|
|
|
@Path("/analytics/artifacts")
|
|
|
|
public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifactsManagementService {
|
|
|
|
public class AnalyticsArtifactsManagementServiceImpl
|
|
|
|
|
|
|
|
implements AnalyticsArtifactsManagementService {
|
|
|
|
private static final Log log = LogFactory.getLog(AnalyticsArtifactsManagementServiceImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(AnalyticsArtifactsManagementServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @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 String
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/stream/{id}")
|
|
|
|
@Path("/stream/{id}")
|
|
|
@ -84,90 +79,70 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
|
|
|
|
EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String streamDefinition = new String(stream.getDefinition().getBytes(), StandardCharsets.UTF_8);
|
|
|
|
String streamDefinition = stream.getDefinition();
|
|
|
|
eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
|
|
|
|
eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
|
|
|
|
if (!isEdited) {
|
|
|
|
if (!isEdited) {
|
|
|
|
eventStreamAdminServiceStub.addEventStreamDefinitionAsString(streamDefinition);
|
|
|
|
eventStreamAdminServiceStub.addEventStreamDefinitionAsString(streamDefinition);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Find and edit stream
|
|
|
|
|
|
|
|
if (eventStreamAdminServiceStub.getStreamDetailsForStreamId(id) != null) {
|
|
|
|
if (eventStreamAdminServiceStub.getStreamDetailsForStreamId(id) != null) {
|
|
|
|
eventStreamAdminServiceStub.editEventStreamDefinitionAsString(streamDefinition, id);
|
|
|
|
eventStreamAdminServiceStub.editEventStreamDefinitionAsString(streamDefinition, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
cleanup(eventStreamAdminServiceStub);
|
|
|
|
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
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/stream")
|
|
|
|
@Path("/stream")
|
|
|
|
public Response deployEventDefinitionAsDto(@Valid EventStream stream) {
|
|
|
|
public Response deployEventDefinitionAsDto(@Valid EventStream stream) {
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
// Categorize attributes to three lists depending on their type
|
|
|
|
|
|
|
|
List<Attribute> metaData = stream.getMetaData();
|
|
|
|
|
|
|
|
List<Attribute> payloadData = stream.getPayloadData();
|
|
|
|
|
|
|
|
List<Attribute> correlationData = stream.getCorrelationData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
/* Conditions
|
|
|
|
deployStream(stream);
|
|
|
|
* - At least one list should always be not null
|
|
|
|
return Response.ok().build();
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (metaData == null && correlationData == null && payloadData == null) {
|
|
|
|
|
|
|
|
log.error("Invalid payload: event attributes");
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Publish the event stream
|
|
|
|
|
|
|
|
publishStream(stream, metaData, correlationData, payloadData);
|
|
|
|
|
|
|
|
return Response.ok().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to create event definitions for tenant " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the remote services for tenant " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to generate jwt token for tenant " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the user store for tenant " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).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
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/receiver/{name}")
|
|
|
|
@Path("/receiver/{name}")
|
|
|
|
public Response deployEventReceiverAsString(@PathParam("name") String name,
|
|
|
|
public Response deployEventReceiverAsString(@PathParam("name") String name,
|
|
|
|
@QueryParam("isEdited") boolean isEdited,
|
|
|
|
@QueryParam("isEdited") boolean isEdited,
|
|
|
|
@Valid EventReceiver receiver) {
|
|
|
|
@Valid Adapter receiver) {
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
EventReceiverAdminServiceStub eventReceiverAdminServiceStub;
|
|
|
|
EventReceiverAdminServiceStub eventReceiverAdminServiceStub;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -178,202 +153,128 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
eventReceiverAdminServiceStub.editActiveEventReceiverConfiguration(receiverDefinition, name);
|
|
|
|
eventReceiverAdminServiceStub.editActiveEventReceiverConfiguration(receiverDefinition, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.ok().build();
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.ok().entity(name).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @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 DTO
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/receiver")
|
|
|
|
@Path("/receiver")
|
|
|
|
public Response deployEventReceiverAsDto(@Valid Adapter receiver) {
|
|
|
|
public Response deployEventReceiverAsDto(@Valid Adapter receiver) {
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String receiverName = receiver.getAdapterName();
|
|
|
|
|
|
|
|
String adapterType = receiver.getAdapterType().toStringFormatted();
|
|
|
|
|
|
|
|
AdapterConfiguration adapterConfiguration = receiver.getAdapterConfiguration();
|
|
|
|
|
|
|
|
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration.getAdapterMappingConfiguration();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<AdapterProperty> adapterProperties = adapterConfiguration.getAdapterProperties();
|
|
|
|
AdapterConfiguration adapterConfiguration = receiver.getAdapterConfiguration();
|
|
|
|
if (adapterProperties == null) {
|
|
|
|
|
|
|
|
log.error("Invalid attribute payload");
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean customMapping = adapterConfiguration.isCustomMappingEnabled();
|
|
|
|
boolean customMapping = adapterConfiguration.isCustomMappingEnabled();
|
|
|
|
List<MappingProperty> inputMappingProperties = adapterMappingConfiguration.getInputMappingProperties();
|
|
|
|
validateAdapterProperties(adapterConfiguration.getAdapterProperties());
|
|
|
|
List<MappingProperty> namespaceMappingProperties = adapterMappingConfiguration.getNamespaceMappingProperties();
|
|
|
|
if (customMapping) {
|
|
|
|
List<MappingProperty> correlationMappingProperties = adapterMappingConfiguration.getCorrelationMappingProperties();
|
|
|
|
validateAdapterMapping(adapterConfiguration.getAdapterMappingConfiguration());
|
|
|
|
List<MappingProperty> payloadMappingProperties = adapterMappingConfiguration.getPayloadMappingProperties();
|
|
|
|
|
|
|
|
List<MappingProperty> metaMappingProperties = adapterMappingConfiguration.getMetaMappingProperties();
|
|
|
|
|
|
|
|
MessageFormat messageFormat = adapterMappingConfiguration.getMessageFormat();
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Conditions
|
|
|
|
|
|
|
|
* - if CustomMappingEnabled check validity of property lists
|
|
|
|
|
|
|
|
* - if both inputMappingProperties and namespaceMappingProperties null check remaining property lists
|
|
|
|
|
|
|
|
* - if all correlationMappingProperties, payloadMappingProperties, metaMappingProperties null log error
|
|
|
|
|
|
|
|
* - if message format is null change the final result to TRUE
|
|
|
|
|
|
|
|
* - else continue
|
|
|
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
if ((customMapping &&
|
|
|
|
|
|
|
|
(inputMappingProperties == null && namespaceMappingProperties == null) &&
|
|
|
|
|
|
|
|
(correlationMappingProperties == null && payloadMappingProperties == null &&
|
|
|
|
|
|
|
|
metaMappingProperties == null)) || messageFormat == null) {
|
|
|
|
|
|
|
|
String errMsg = "Invalid mapping payload";
|
|
|
|
|
|
|
|
log.error(errMsg);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String eventStreamWithVersion = receiver.getEventStreamWithVersion();
|
|
|
|
deployReceiver(receiver, customMapping, adapterConfiguration);
|
|
|
|
|
|
|
|
|
|
|
|
publishReceiver(receiverName, adapterType, adapterProperties, customMapping, inputMappingProperties,
|
|
|
|
|
|
|
|
namespaceMappingProperties, correlationMappingProperties, payloadMappingProperties,
|
|
|
|
|
|
|
|
metaMappingProperties, messageFormat, eventStreamWithVersion);
|
|
|
|
|
|
|
|
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);
|
|
|
|
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).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
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/publisher/{name}")
|
|
|
|
@Path("/publisher/{name}")
|
|
|
|
public Response deployEventPublisherAsString(@PathParam("name") String name,
|
|
|
|
public Response deployEventPublisherAsString(@PathParam("name") String name,
|
|
|
|
@QueryParam("isEdited") boolean isEdited,
|
|
|
|
@QueryParam("isEdited") boolean isEdited,
|
|
|
|
@Valid EventPublisher publisher) {
|
|
|
|
@Valid Adapter publisher) {
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
EventPublisherAdminServiceStub eventPublisherAdminServiceStub;
|
|
|
|
EventPublisherAdminServiceStub eventPublisherAdminServiceStub;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String publisherDefinition = publisher.getDefinition();
|
|
|
|
String publisherDefinition = publisher.getDefinition();
|
|
|
|
|
|
|
|
|
|
|
|
eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub();
|
|
|
|
eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub();
|
|
|
|
if (!isEdited) {
|
|
|
|
if (!isEdited) {
|
|
|
|
eventPublisherAdminServiceStub.deployEventPublisherConfiguration(publisherDefinition);
|
|
|
|
eventPublisherAdminServiceStub.deployEventPublisherConfiguration(publisherDefinition);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
eventPublisherAdminServiceStub.editActiveEventPublisherConfiguration(publisherDefinition, name);
|
|
|
|
eventPublisherAdminServiceStub.editActiveEventPublisherConfiguration(publisherDefinition, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.ok().build();
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
log.error("Failed to create event definitions for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.ok().entity(publisher).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @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 DTO
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/publisher")
|
|
|
|
@Path("/publisher")
|
|
|
|
public Response deployEventPublisherAsDto(@Valid Adapter publisher) {
|
|
|
|
public Response deployEventPublisherAsDto(@Valid Adapter publisher) {
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
String publisherName = publisher.getAdapterName();
|
|
|
|
|
|
|
|
String adapterType = publisher.getAdapterType().toStringFormatted();
|
|
|
|
|
|
|
|
AdapterConfiguration adapterConfiguration = publisher.getAdapterConfiguration();
|
|
|
|
AdapterConfiguration adapterConfiguration = publisher.getAdapterConfiguration();
|
|
|
|
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration.getAdapterMappingConfiguration();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<AdapterProperty> adapterProperties = adapterConfiguration.getAdapterProperties();
|
|
|
|
validateAdapterProperties(adapterConfiguration.getAdapterProperties());
|
|
|
|
if (adapterProperties == null) {
|
|
|
|
|
|
|
|
log.error("Invalid attribute payload");
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean customMapping = adapterConfiguration.isCustomMappingEnabled();
|
|
|
|
boolean customMapping = adapterConfiguration.isCustomMappingEnabled();
|
|
|
|
String inputMappingString = adapterMappingConfiguration.getInputMappingString();
|
|
|
|
if (customMapping) {
|
|
|
|
List<MappingProperty> inputMappingProperties = adapterMappingConfiguration.getInputMappingProperties();
|
|
|
|
validateAdapterMapping(adapterConfiguration.getAdapterMappingConfiguration());
|
|
|
|
List<MappingProperty> correlationMappingProperties = adapterMappingConfiguration.getCorrelationMappingProperties();
|
|
|
|
|
|
|
|
List<MappingProperty> payloadMappingProperties = adapterMappingConfiguration.getPayloadMappingProperties();
|
|
|
|
|
|
|
|
List<MappingProperty> metaMappingProperties = adapterMappingConfiguration.getMetaMappingProperties();
|
|
|
|
|
|
|
|
MessageFormat messageFormat = adapterMappingConfiguration.getMessageFormat();
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Conditions
|
|
|
|
|
|
|
|
* - if CustomMappingEnabled check validity of property lists
|
|
|
|
|
|
|
|
* - if all correlationMappingProperties, payloadMappingProperties, metaMappingProperties null log error
|
|
|
|
|
|
|
|
* - if message format is null change the final result to TRUE
|
|
|
|
|
|
|
|
* - else continue
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((customMapping &&
|
|
|
|
|
|
|
|
(inputMappingProperties == null && inputMappingString == null) &&
|
|
|
|
|
|
|
|
(correlationMappingProperties == null && payloadMappingProperties == null &&
|
|
|
|
|
|
|
|
metaMappingProperties == null)) || messageFormat == null) {
|
|
|
|
|
|
|
|
String errMsg = "Invalid mapping payload";
|
|
|
|
|
|
|
|
log.error(errMsg);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String eventStreamWithVersion = publisher.getEventStreamWithVersion();
|
|
|
|
deployPublisher(publisher, customMapping, adapterConfiguration);
|
|
|
|
|
|
|
|
|
|
|
|
publishPublisher(publisherName, adapterType, adapterProperties, customMapping
|
|
|
|
|
|
|
|
, inputMappingString, inputMappingProperties, correlationMappingProperties
|
|
|
|
|
|
|
|
, payloadMappingProperties, metaMappingProperties, messageFormat
|
|
|
|
|
|
|
|
, eventStreamWithVersion);
|
|
|
|
|
|
|
|
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);
|
|
|
|
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
log.error("Failed to generate jwt token for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @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
|
|
|
|
|
|
|
|
* Function - Used to deploy Siddhi script as an artifact using a String
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/siddhi-script/{name}")
|
|
|
|
@Path("/siddhi-script/{name}")
|
|
|
@ -385,38 +286,46 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
publishSiddhiExecutionPlan(name, isEdited, plan.getDefinition());
|
|
|
|
publishSiddhiExecutionPlan(name, isEdited, plan.getDefinition());
|
|
|
|
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);
|
|
|
|
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
log.error("Failed to connect with the remote services for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
} catch (InvalidExecutionPlanException e) {
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
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);
|
|
|
|
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Failed to connect with the user store for tenantDomain: " + tenantDomain, e);
|
|
|
|
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
log.error(errMsg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param stream Stream definition
|
|
|
|
* Set data to a Stream dto and deploy dto through a stub
|
|
|
|
* @param metaData Meta attributes of the stream
|
|
|
|
*
|
|
|
|
* @param correlationData Correlation attributes of the stream
|
|
|
|
* @param stream Stream definition
|
|
|
|
* @param payloadData Payload attributes of the stream
|
|
|
|
|
|
|
|
* @throws RemoteException exception that may occur during a remote method call
|
|
|
|
|
|
|
|
* @throws UserStoreException exception that may occur during JWT token generation
|
|
|
|
|
|
|
|
* @throws JWTClientException exception that may occur during connecting to client store
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void publishStream(EventStream stream, List<Attribute> metaData,
|
|
|
|
private void deployStream(EventStream stream)
|
|
|
|
List<Attribute> correlationData, List<Attribute> payloadData)
|
|
|
|
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException {
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException {
|
|
|
|
EventStreamAdminServiceStub eventStreamAdminServiceStub =
|
|
|
|
EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
|
|
|
|
DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
|
|
|
|
List<Attribute> metaData = stream.getMetaData();
|
|
|
|
|
|
|
|
List<Attribute> payloadData = stream.getPayloadData();
|
|
|
|
|
|
|
|
List<Attribute> correlationData = stream.getCorrelationData();
|
|
|
|
|
|
|
|
if (metaData.isEmpty() && correlationData.isEmpty() && payloadData.isEmpty()) {
|
|
|
|
|
|
|
|
String errMsg = String.format("Failed to validate Stream property attributes of %s:%s",
|
|
|
|
|
|
|
|
stream.getName(), stream.getVersion());
|
|
|
|
|
|
|
|
ErrorResponse errorResponse = new ErrorResponse();
|
|
|
|
|
|
|
|
errorResponse.setMessage(errMsg);
|
|
|
|
|
|
|
|
log.error(errMsg);
|
|
|
|
|
|
|
|
throw new BadRequestException(errorResponse);
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
eventStreamAdminServiceStub = DeviceMgtAPIUtils.getEventStreamAdminServiceStub();
|
|
|
|
|
|
|
|
|
|
|
|
EventStreamDefinitionDto eventStreamDefinitionDto = new EventStreamDefinitionDto();
|
|
|
|
EventStreamDefinitionDto eventStreamDefinitionDto = new EventStreamDefinitionDto();
|
|
|
|
eventStreamDefinitionDto.setName(stream.getName());
|
|
|
|
eventStreamDefinitionDto.setName(stream.getName());
|
|
|
|
eventStreamDefinitionDto.setVersion(stream.getVersion());
|
|
|
|
eventStreamDefinitionDto.setVersion(stream.getVersion());
|
|
|
@ -425,6 +334,7 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
eventStreamDefinitionDto.setMetaData(addEventAttributesToDto(metaData));
|
|
|
|
eventStreamDefinitionDto.setMetaData(addEventAttributesToDto(metaData));
|
|
|
|
eventStreamDefinitionDto.setPayloadData(addEventAttributesToDto(payloadData));
|
|
|
|
eventStreamDefinitionDto.setPayloadData(addEventAttributesToDto(payloadData));
|
|
|
|
eventStreamDefinitionDto.setCorrelationData(addEventAttributesToDto(correlationData));
|
|
|
|
eventStreamDefinitionDto.setCorrelationData(addEventAttributesToDto(correlationData));
|
|
|
|
|
|
|
|
|
|
|
|
String streamId = stream.getName() + ":" + stream.getVersion();
|
|
|
|
String streamId = stream.getName() + ":" + stream.getVersion();
|
|
|
|
if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) != null) {
|
|
|
|
if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) != null) {
|
|
|
|
eventStreamAdminServiceStub.editEventStreamDefinitionAsDto(eventStreamDefinitionDto, streamId);
|
|
|
|
eventStreamAdminServiceStub.editEventStreamDefinitionAsDto(eventStreamDefinitionDto, streamId);
|
|
|
@ -438,86 +348,75 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param receiverName Receiver name
|
|
|
|
* Set data to a receiver dto and deploy dto through a stub
|
|
|
|
* @param adapterType Receiver type
|
|
|
|
*
|
|
|
|
* @param adapterProperties Receiver properties
|
|
|
|
* @param receiver Event Receiver adapter
|
|
|
|
* @param customMapping Is receiver mapped
|
|
|
|
* @param customMapping Is Receiver mapped
|
|
|
|
* @param inputMappingProperties Receiver input attribute mapping
|
|
|
|
* @param adapterConfiguration Adapter property and mapping configuration
|
|
|
|
* @param namespaceMappingProperties Receiver name-scape attribute mapping
|
|
|
|
* @throws RemoteException Exception that may occur during a remote method call
|
|
|
|
* @param correlationMappingProperties Receiver correlation attribute mapping
|
|
|
|
* @throws UserStoreException Exception that may occur during JWT token generation
|
|
|
|
* @param payloadMappingProperties Receiver payload attribute mapping
|
|
|
|
* @throws JWTClientException Exception that may occur during connecting to client store
|
|
|
|
* @param metaMappingProperties Receiver meta attribute mapping
|
|
|
|
|
|
|
|
* @param messageFormat Receiver mapping format
|
|
|
|
|
|
|
|
* @param eventStreamWithVersion Attached stream
|
|
|
|
|
|
|
|
* @throws RemoteException exception that may occur during a remote method call
|
|
|
|
|
|
|
|
* @throws UserStoreException exception that may occur during JWT token generation
|
|
|
|
|
|
|
|
* @throws JWTClientException exception that may occur during connecting to client store
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void publishReceiver(String receiverName, String adapterType,
|
|
|
|
private void deployReceiver(Adapter receiver, boolean customMapping,
|
|
|
|
List<AdapterProperty> adapterProperties, boolean customMapping,
|
|
|
|
AdapterConfiguration adapterConfiguration)
|
|
|
|
List<MappingProperty> inputMappingProperties,
|
|
|
|
|
|
|
|
List<MappingProperty> namespaceMappingProperties,
|
|
|
|
|
|
|
|
List<MappingProperty> correlationMappingProperties,
|
|
|
|
|
|
|
|
List<MappingProperty> payloadMappingProperties,
|
|
|
|
|
|
|
|
List<MappingProperty> metaMappingProperties,
|
|
|
|
|
|
|
|
MessageFormat messageFormat,
|
|
|
|
|
|
|
|
String eventStreamWithVersion)
|
|
|
|
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException {
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException {
|
|
|
|
EventReceiverAdminServiceStub eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
|
|
|
|
EventReceiverAdminServiceStub eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
String receiverName = receiver.getAdapterName();
|
|
|
|
|
|
|
|
String adapterType = receiver.getAdapterType().toStringFormatted();
|
|
|
|
|
|
|
|
String eventStreamWithVersion = receiver.getEventStreamWithVersion();
|
|
|
|
|
|
|
|
List<AdapterProperty> adapterProperties = adapterConfiguration.getAdapterProperties();
|
|
|
|
EventReceiverConfigurationDto eventReceiverConfigurationDto = eventReceiverAdminServiceStub
|
|
|
|
EventReceiverConfigurationDto eventReceiverConfigurationDto = eventReceiverAdminServiceStub
|
|
|
|
.getActiveEventReceiverConfiguration(receiverName);
|
|
|
|
.getActiveEventReceiverConfiguration(receiverName);
|
|
|
|
|
|
|
|
|
|
|
|
// Check if adapter already exists, if so un-deploy it
|
|
|
|
|
|
|
|
if (eventReceiverConfigurationDto != null) {
|
|
|
|
if (eventReceiverConfigurationDto != null) {
|
|
|
|
eventReceiverAdminServiceStub.undeployActiveEventReceiverConfiguration(receiverName);
|
|
|
|
eventReceiverAdminServiceStub.undeployActiveEventReceiverConfiguration(receiverName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicInputAdapterPropertyDto[] basicInputAdapterPropertyDtos = addReceiverConfigToDto(adapterProperties);
|
|
|
|
|
|
|
|
|
|
|
|
// Adding attribute properties to DTOs
|
|
|
|
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration.getAdapterMappingConfiguration();
|
|
|
|
BasicInputAdapterPropertyDto[] basicInputAdapterPropertyDtos =
|
|
|
|
MessageFormat messageFormat = adapterMappingConfiguration.getMessageFormat();
|
|
|
|
addReceiverConfigToDto(adapterProperties);
|
|
|
|
if (!messageFormat.toString().equals("wso2event")) {
|
|
|
|
|
|
|
|
EventMappingPropertyDto[] inputMappingPropertyDtos =
|
|
|
|
if (eventReceiverAdminServiceStub.getActiveEventReceiverConfiguration(receiverName) == null) {
|
|
|
|
addReceiverMappingToDto(adapterMappingConfiguration.getInputMappingProperties());
|
|
|
|
// Call stub deploy methods according to the message format
|
|
|
|
if (messageFormat.toString().equals("xml")) {
|
|
|
|
if (!messageFormat.toString().equals("wso2event")) {
|
|
|
|
EventMappingPropertyDto[] namespaceMappingPropertyDtos =
|
|
|
|
EventMappingPropertyDto[] inputMappingPropertyDtos =
|
|
|
|
addReceiverMappingToDto(adapterMappingConfiguration.getNamespaceMappingProperties());
|
|
|
|
addReceiverMappingToDto(inputMappingProperties);
|
|
|
|
eventReceiverAdminServiceStub.deployXmlEventReceiverConfiguration(receiverName
|
|
|
|
if (messageFormat.toString().equals("xml")) {
|
|
|
|
, eventStreamWithVersion, adapterType, null
|
|
|
|
EventMappingPropertyDto[] namespaceMappingPropertyDtos =
|
|
|
|
, namespaceMappingPropertyDtos, inputMappingPropertyDtos
|
|
|
|
addReceiverMappingToDto(namespaceMappingProperties);
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
eventReceiverAdminServiceStub.deployXmlEventReceiverConfiguration(receiverName
|
|
|
|
if (messageFormat.toString().equals("map")) {
|
|
|
|
, eventStreamWithVersion, adapterType, null
|
|
|
|
eventReceiverAdminServiceStub.deployMapEventReceiverConfiguration(receiverName
|
|
|
|
, namespaceMappingPropertyDtos, inputMappingPropertyDtos
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
|
|
|
|
} else if (messageFormat.toString().equals("text")) {
|
|
|
|
|
|
|
|
eventReceiverAdminServiceStub.deployTextEventReceiverConfiguration(receiverName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (messageFormat.toString().equals("map")) {
|
|
|
|
eventReceiverAdminServiceStub.deployJsonEventReceiverConfiguration(receiverName
|
|
|
|
eventReceiverAdminServiceStub.deployMapEventReceiverConfiguration(receiverName
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
|
|
|
|
} else if (messageFormat.toString().equals("text")) {
|
|
|
|
|
|
|
|
eventReceiverAdminServiceStub.deployTextEventReceiverConfiguration(receiverName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
eventReceiverAdminServiceStub.deployJsonEventReceiverConfiguration(receiverName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
EventMappingPropertyDto[] correlationMappingPropertyDtos = addReceiverMappingToDto(correlationMappingProperties);
|
|
|
|
|
|
|
|
EventMappingPropertyDto[] metaMappingPropertyDtos = addReceiverMappingToDto(metaMappingProperties);
|
|
|
|
|
|
|
|
EventMappingPropertyDto[] payloadMappingPropertyDtos = addReceiverMappingToDto(payloadMappingProperties);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventReceiverAdminServiceStub.deployWso2EventReceiverConfiguration(receiverName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, metaMappingPropertyDtos
|
|
|
|
|
|
|
|
, correlationMappingPropertyDtos, payloadMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping
|
|
|
|
|
|
|
|
, eventStreamWithVersion);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
EventMappingPropertyDto[] correlationMappingPropertyDtos = addReceiverMappingToDto(
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getCorrelationMappingProperties()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
EventMappingPropertyDto[] metaMappingPropertyDtos = addReceiverMappingToDto(
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getInputMappingProperties()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
EventMappingPropertyDto[] payloadMappingPropertyDtos = addReceiverMappingToDto(
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getPayloadMappingProperties()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventReceiverAdminServiceStub.deployWso2EventReceiverConfiguration(receiverName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, metaMappingPropertyDtos
|
|
|
|
|
|
|
|
, correlationMappingPropertyDtos, payloadMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicInputAdapterPropertyDtos, customMapping
|
|
|
|
|
|
|
|
, eventStreamWithVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
cleanup(eventReceiverAdminServiceStub);
|
|
|
|
cleanup(eventReceiverAdminServiceStub);
|
|
|
@ -525,120 +424,115 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param publisherName Publisher name
|
|
|
|
* Set data to a publisher dto and deploy dto through a stub
|
|
|
|
* @param adapterType Publisher type
|
|
|
|
*
|
|
|
|
* @param adapterProperties Publisher properties
|
|
|
|
* @param publisher Event Publisher adapter
|
|
|
|
* @param customMapping Is publisher mapped
|
|
|
|
* @param customMapping Is Publisher mapped
|
|
|
|
* @param correlationMappingProperties Publisher correlation attribute mapping
|
|
|
|
* @param adapterConfiguration Publisher property and mapping configuration
|
|
|
|
* @param payloadMappingProperties Publisher payload attribute mapping
|
|
|
|
* @throws RemoteException Exception that may occur during a remote method call
|
|
|
|
* @param metaMappingProperties Publisher meta attribute mapping
|
|
|
|
* @throws UserStoreException Exception that may occur during JWT token generation
|
|
|
|
* @param messageFormat Publisher mapping format
|
|
|
|
* @throws JWTClientException Exception that may occur during connecting to client store
|
|
|
|
* @param eventStreamWithVersion Attached stream
|
|
|
|
|
|
|
|
* @throws RemoteException exception that may occur during a remote method call
|
|
|
|
|
|
|
|
* @throws UserStoreException exception that may occur during JWT token generation
|
|
|
|
|
|
|
|
* @throws JWTClientException exception that may occur during connecting to client store
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void publishPublisher(String publisherName, String adapterType,
|
|
|
|
private void deployPublisher(Adapter publisher, boolean customMapping,
|
|
|
|
List<AdapterProperty> adapterProperties,
|
|
|
|
AdapterConfiguration adapterConfiguration)
|
|
|
|
boolean customMapping,
|
|
|
|
|
|
|
|
String inputMappingString,
|
|
|
|
|
|
|
|
List<MappingProperty> inputMappingProperties,
|
|
|
|
|
|
|
|
List<MappingProperty> correlationMappingProperties,
|
|
|
|
|
|
|
|
List<MappingProperty> payloadMappingProperties,
|
|
|
|
|
|
|
|
List<MappingProperty> metaMappingProperties,
|
|
|
|
|
|
|
|
MessageFormat messageFormat,
|
|
|
|
|
|
|
|
String eventStreamWithVersion)
|
|
|
|
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException {
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException {
|
|
|
|
EventPublisherAdminServiceStub eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub();
|
|
|
|
EventPublisherAdminServiceStub eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub();
|
|
|
|
// Check if adapter already exists, if so un-deploy it
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
String publisherName = publisher.getAdapterName();
|
|
|
|
|
|
|
|
String adapterType = publisher.getAdapterType().toStringFormatted();
|
|
|
|
|
|
|
|
String eventStreamWithVersion = publisher.getEventStreamWithVersion();
|
|
|
|
|
|
|
|
List<AdapterProperty> adapterProperties = adapterConfiguration.getAdapterProperties();
|
|
|
|
EventPublisherConfigurationDto eventPublisherConfigurationDto = eventPublisherAdminServiceStub
|
|
|
|
EventPublisherConfigurationDto eventPublisherConfigurationDto = eventPublisherAdminServiceStub
|
|
|
|
.getActiveEventPublisherConfiguration(publisherName);
|
|
|
|
.getActiveEventPublisherConfiguration(publisherName);
|
|
|
|
if (eventPublisherConfigurationDto != null) {
|
|
|
|
if (eventPublisherConfigurationDto != null) {
|
|
|
|
eventPublisherAdminServiceStub.undeployActiveEventPublisherConfiguration(publisherName);
|
|
|
|
eventPublisherAdminServiceStub.undeployActiveEventPublisherConfiguration(publisherName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Adding attribute properties to DTOs
|
|
|
|
|
|
|
|
BasicOutputAdapterPropertyDto[] basicOutputAdapterPropertyDtos =
|
|
|
|
BasicOutputAdapterPropertyDto[] basicOutputAdapterPropertyDtos =
|
|
|
|
addPublisherConfigToDto(adapterProperties);
|
|
|
|
addPublisherConfigToDto(adapterProperties);
|
|
|
|
|
|
|
|
|
|
|
|
if (eventPublisherAdminServiceStub.getActiveEventPublisherConfiguration(publisherName) == null) {
|
|
|
|
AdapterMappingConfiguration adapterMappingConfiguration = adapterConfiguration.getAdapterMappingConfiguration();
|
|
|
|
// Call stub deploy methods according to the message format
|
|
|
|
MessageFormat messageFormat = adapterMappingConfiguration.getMessageFormat();
|
|
|
|
if (!messageFormat.toString().equals("wso2event")) {
|
|
|
|
if (!messageFormat.toString().equals("wso2event")) {
|
|
|
|
if (!messageFormat.toString().equals("map")) {
|
|
|
|
if (!messageFormat.toString().equals("map")) {
|
|
|
|
if (messageFormat.toString().equals("xml")) {
|
|
|
|
if (messageFormat.toString().equals("xml")) {
|
|
|
|
eventPublisherAdminServiceStub.deployXmlEventPublisherConfiguration(publisherName
|
|
|
|
eventPublisherAdminServiceStub.deployXmlEventPublisherConfiguration(publisherName
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingString
|
|
|
|
, eventStreamWithVersion, adapterType, adapterMappingConfiguration.getInputMappingString()
|
|
|
|
, basicOutputAdapterPropertyDtos, eventStreamWithVersion
|
|
|
|
, basicOutputAdapterPropertyDtos, eventStreamWithVersion
|
|
|
|
, customMapping);
|
|
|
|
, customMapping);
|
|
|
|
} else if (messageFormat.toString().equals("text")) {
|
|
|
|
} else if (messageFormat.toString().equals("text")) {
|
|
|
|
eventPublisherAdminServiceStub.deployTextEventPublisherConfiguration(publisherName
|
|
|
|
eventPublisherAdminServiceStub.deployTextEventPublisherConfiguration(publisherName
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingString
|
|
|
|
, eventStreamWithVersion, adapterType, adapterMappingConfiguration.getInputMappingString()
|
|
|
|
, basicOutputAdapterPropertyDtos, eventStreamWithVersion
|
|
|
|
, basicOutputAdapterPropertyDtos, eventStreamWithVersion
|
|
|
|
, customMapping);
|
|
|
|
, customMapping);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
eventPublisherAdminServiceStub.deployJsonEventPublisherConfiguration(publisherName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingString
|
|
|
|
|
|
|
|
, basicOutputAdapterPropertyDtos, eventStreamWithVersion
|
|
|
|
|
|
|
|
, customMapping);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] inputMappingPropertyDtos =
|
|
|
|
eventPublisherAdminServiceStub.deployJsonEventPublisherConfiguration(publisherName
|
|
|
|
addPublisherMappingToDto(inputMappingProperties);
|
|
|
|
, eventStreamWithVersion, adapterType, adapterMappingConfiguration.getInputMappingString()
|
|
|
|
eventPublisherAdminServiceStub.deployMapEventPublisherConfiguration(publisherName
|
|
|
|
, basicOutputAdapterPropertyDtos, eventStreamWithVersion
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
, customMapping);
|
|
|
|
, basicOutputAdapterPropertyDtos, customMapping);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] correlationMappingPropertyDtos =
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] inputMappingPropertyDtos =
|
|
|
|
addPublisherMappingToDto(correlationMappingProperties);
|
|
|
|
addPublisherMappingToDto(
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] metaMappingPropertyDtos =
|
|
|
|
adapterMappingConfiguration.getInputMappingProperties()
|
|
|
|
addPublisherMappingToDto(metaMappingProperties);
|
|
|
|
);
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] payloadMappingPropertyDtos =
|
|
|
|
eventPublisherAdminServiceStub.deployMapEventPublisherConfiguration(publisherName
|
|
|
|
addPublisherMappingToDto(payloadMappingProperties);
|
|
|
|
, eventStreamWithVersion, adapterType, inputMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicOutputAdapterPropertyDtos, customMapping);
|
|
|
|
eventPublisherAdminServiceStub.deployWSO2EventPublisherConfiguration(publisherName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, metaMappingPropertyDtos
|
|
|
|
|
|
|
|
, correlationMappingPropertyDtos, payloadMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicOutputAdapterPropertyDtos, customMapping
|
|
|
|
|
|
|
|
, eventStreamWithVersion);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] correlationMappingPropertyDtos =
|
|
|
|
|
|
|
|
addPublisherMappingToDto(
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getCorrelationMappingProperties()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] metaMappingPropertyDtos =
|
|
|
|
|
|
|
|
addPublisherMappingToDto(
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getMetaMappingProperties()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] payloadMappingPropertyDtos =
|
|
|
|
|
|
|
|
addPublisherMappingToDto(
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getPayloadMappingProperties()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
eventPublisherAdminServiceStub.deployWSO2EventPublisherConfiguration(publisherName
|
|
|
|
|
|
|
|
, eventStreamWithVersion, adapterType, metaMappingPropertyDtos
|
|
|
|
|
|
|
|
, correlationMappingPropertyDtos, payloadMappingPropertyDtos
|
|
|
|
|
|
|
|
, basicOutputAdapterPropertyDtos, customMapping
|
|
|
|
|
|
|
|
, eventStreamWithVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
cleanup(eventPublisherAdminServiceStub);
|
|
|
|
cleanup(eventPublisherAdminServiceStub);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param name plan name
|
|
|
|
* Publish a siddhi execution plan using a stub
|
|
|
|
* @param isEdited is plan edited
|
|
|
|
*
|
|
|
|
* @param plan plan data
|
|
|
|
* @param name Plan name
|
|
|
|
* @throws RemoteException exception that may occur during a remote method call
|
|
|
|
* @param isEdited Is plan edited
|
|
|
|
* @throws UserStoreException exception that may occur during JWT token generation
|
|
|
|
* @param plan Plan data
|
|
|
|
* @throws JWTClientException exception that may occur during connecting to client store
|
|
|
|
* @throws RemoteException Exception that may occur during a remote method call
|
|
|
|
* @throws InvalidExecutionPlanException exception that may occur if execution plan validation fails
|
|
|
|
* @throws UserStoreException Exception that may occur during JWT token generation
|
|
|
|
|
|
|
|
* @throws JWTClientException Exception that may occur during connecting to client store
|
|
|
|
|
|
|
|
* @throws InvalidExecutionPlanException Exception that may occur if execution plan validation fails
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void publishSiddhiExecutionPlan(String name, boolean isEdited,
|
|
|
|
private void publishSiddhiExecutionPlan(String name, boolean isEdited,
|
|
|
|
String plan)
|
|
|
|
String plan)
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException,
|
|
|
|
throws RemoteException, UserStoreException, JWTClientException {
|
|
|
|
InvalidExecutionPlanException {
|
|
|
|
|
|
|
|
EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null;
|
|
|
|
EventProcessorAdminServiceStub eventProcessorAdminServiceStub = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
eventProcessorAdminServiceStub = DeviceMgtAPIUtils.getEventProcessorAdminServiceStub();
|
|
|
|
eventProcessorAdminServiceStub = DeviceMgtAPIUtils.getEventProcessorAdminServiceStub();
|
|
|
|
// Validate the plan code
|
|
|
|
|
|
|
|
String validationResponse = eventProcessorAdminServiceStub.validateExecutionPlan(plan);
|
|
|
|
String validationResponse = eventProcessorAdminServiceStub.validateExecutionPlan(plan);
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
if (!isEdited) {
|
|
|
|
if (!isEdited) {
|
|
|
|
// Create a new plan
|
|
|
|
|
|
|
|
eventProcessorAdminServiceStub.deployExecutionPlan(plan);
|
|
|
|
eventProcessorAdminServiceStub.deployExecutionPlan(plan);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Edit plan
|
|
|
|
|
|
|
|
eventProcessorAdminServiceStub.editActiveExecutionPlan(plan, name);
|
|
|
|
eventProcessorAdminServiceStub.editActiveExecutionPlan(plan, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ErrorDTO errorDTO = new ErrorDTO();
|
|
|
|
ErrorDTO errorDTO = new ErrorDTO();
|
|
|
|
errorDTO.setMessage(validationResponse);
|
|
|
|
errorDTO.setMessage(validationResponse);
|
|
|
|
|
|
|
|
log.error(validationResponse);
|
|
|
|
throw new InvalidExecutionPlanException(errorDTO);
|
|
|
|
throw new InvalidExecutionPlanException(errorDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -646,18 +540,74 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This will set payload of event attribute's mapping to the DTO
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param attributes list of event attributes
|
|
|
|
|
|
|
|
* @return DTO with all the event attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
private EventStreamAttributeDto[] addEventAttributesToDto(List<Attribute> attributes) {
|
|
|
|
private EventStreamAttributeDto[] addEventAttributesToDto(List<Attribute> attributes) {
|
|
|
|
EventStreamAttributeDto[] eventStreamAttributeDtos = new EventStreamAttributeDto[attributes.size()];
|
|
|
|
EventStreamAttributeDto[] eventStreamAttributeDtos = new EventStreamAttributeDto[attributes.size()];
|
|
|
|
for (int i = 0; i < attributes.size(); i++) {
|
|
|
|
for (Attribute attribute : attributes) {
|
|
|
|
EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto();
|
|
|
|
EventStreamAttributeDto eventStreamAttributeDto = new EventStreamAttributeDto();
|
|
|
|
eventStreamAttributeDto.setAttributeName(attributes.get(i).getName());
|
|
|
|
eventStreamAttributeDto.setAttributeName(attribute.getName());
|
|
|
|
eventStreamAttributeDto.setAttributeType(attributes.get(i).getType().toString());
|
|
|
|
eventStreamAttributeDto.setAttributeType(attribute.getType().toString());
|
|
|
|
eventStreamAttributeDtos[i] = eventStreamAttributeDto;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eventStreamAttributeDtos;
|
|
|
|
return eventStreamAttributeDtos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Validate adapter payload attributes
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param adapterProperties Adapter payload attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void validateAdapterProperties(List<AdapterProperty> adapterProperties) {
|
|
|
|
|
|
|
|
if (adapterProperties.isEmpty()) {
|
|
|
|
|
|
|
|
String errMsg = "Invalid payload: event property attributes invalid!!!";
|
|
|
|
|
|
|
|
ErrorResponse errorResponse = new ErrorResponse();
|
|
|
|
|
|
|
|
errorResponse.setMessage(errMsg);
|
|
|
|
|
|
|
|
log.error(errMsg);
|
|
|
|
|
|
|
|
throw new BadRequestException(errorResponse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Validate adapter mapping attributes
|
|
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
|
|
* Conditions
|
|
|
|
|
|
|
|
* - if both inputMappingProperties and namespaceMappingProperties null check remaining property lists
|
|
|
|
|
|
|
|
* - if all correlationMappingProperties, payloadMappingProperties, metaMappingProperties null log error
|
|
|
|
|
|
|
|
* - if message format is null change the final result to TRUE
|
|
|
|
|
|
|
|
* - else continue
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param adapterMappingConfiguration Adapter mapping attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void validateAdapterMapping(AdapterMappingConfiguration adapterMappingConfiguration) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (adapterMappingConfiguration.getInputMappingString() == null &&
|
|
|
|
|
|
|
|
(adapterMappingConfiguration.getInputMappingProperties().isEmpty() &&
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getNamespaceMappingProperties().isEmpty()) &&
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getCorrelationMappingProperties().isEmpty() &&
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getPayloadMappingProperties().isEmpty() &&
|
|
|
|
|
|
|
|
adapterMappingConfiguration.getMetaMappingProperties().isEmpty()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|| adapterMappingConfiguration.getMessageFormat() == null) {
|
|
|
|
|
|
|
|
String errMsg = "Invalid payload: event mapping attributes invalid!!!";
|
|
|
|
|
|
|
|
ErrorResponse errorResponse = new ErrorResponse();
|
|
|
|
|
|
|
|
errorResponse.setMessage(errMsg);
|
|
|
|
|
|
|
|
log.error(errMsg);
|
|
|
|
|
|
|
|
throw new BadRequestException(errorResponse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This will set payload of receiver attributes to the DTO
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param adapterProperties List of receiver attributes
|
|
|
|
|
|
|
|
* @return DTO with all the receiver attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
private BasicInputAdapterPropertyDto[] addReceiverConfigToDto(
|
|
|
|
private BasicInputAdapterPropertyDto[] addReceiverConfigToDto(
|
|
|
|
List<AdapterProperty> adapterProperties) {
|
|
|
|
List<AdapterProperty> adapterProperties) {
|
|
|
|
BasicInputAdapterPropertyDto[] basicInputAdapterPropertyDtos
|
|
|
|
BasicInputAdapterPropertyDto[] basicInputAdapterPropertyDtos
|
|
|
@ -671,7 +621,14 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
return basicInputAdapterPropertyDtos;
|
|
|
|
return basicInputAdapterPropertyDtos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private EventMappingPropertyDto[] addReceiverMappingToDto(List<MappingProperty> mapProperties) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This will set payload of receiver mapping attributes to the DTO
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param mapProperties List of receiver mapping attributes
|
|
|
|
|
|
|
|
* @return DTO with all the receiver mapping attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private EventMappingPropertyDto[] addReceiverMappingToDto
|
|
|
|
|
|
|
|
(List<MappingProperty> mapProperties) {
|
|
|
|
EventMappingPropertyDto[] eventMappingPropertyDtos = new EventMappingPropertyDto[mapProperties.size()];
|
|
|
|
EventMappingPropertyDto[] eventMappingPropertyDtos = new EventMappingPropertyDto[mapProperties.size()];
|
|
|
|
for (int i = 0; i < mapProperties.size(); i++) {
|
|
|
|
for (int i = 0; i < mapProperties.size(); i++) {
|
|
|
|
EventMappingPropertyDto eventMappingPropertyDto = new EventMappingPropertyDto();
|
|
|
|
EventMappingPropertyDto eventMappingPropertyDto = new EventMappingPropertyDto();
|
|
|
@ -683,6 +640,12 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
return eventMappingPropertyDtos;
|
|
|
|
return eventMappingPropertyDtos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This will set payload of publisher attributes to the DTO
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param adapterProperties List of publisher attributes
|
|
|
|
|
|
|
|
* @return DTO with all the publisher attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
private BasicOutputAdapterPropertyDto[] addPublisherConfigToDto(
|
|
|
|
private BasicOutputAdapterPropertyDto[] addPublisherConfigToDto(
|
|
|
|
List<AdapterProperty> adapterProperties) {
|
|
|
|
List<AdapterProperty> adapterProperties) {
|
|
|
|
BasicOutputAdapterPropertyDto[] basicOutputAdapterPropertyDtos =
|
|
|
|
BasicOutputAdapterPropertyDto[] basicOutputAdapterPropertyDtos =
|
|
|
@ -697,8 +660,14 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
return basicOutputAdapterPropertyDtos;
|
|
|
|
return basicOutputAdapterPropertyDtos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This will set payload of publisher mapping attributes to the DTO
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param mapProperties List of publisher mapping attributes
|
|
|
|
|
|
|
|
* @return DTO with all the publisher mapping attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
private org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] addPublisherMappingToDto
|
|
|
|
private org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] addPublisherMappingToDto
|
|
|
|
(List<MappingProperty> mapProperties) {
|
|
|
|
(List<MappingProperty> mapProperties) {
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] eventMappingPropertyDtos
|
|
|
|
org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[] eventMappingPropertyDtos
|
|
|
|
= new org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[mapProperties.size()];
|
|
|
|
= new org.wso2.carbon.event.publisher.stub.types.EventMappingPropertyDto[mapProperties.size()];
|
|
|
|
for (int i = 0; i < mapProperties.size(); i++) {
|
|
|
|
for (int i = 0; i < mapProperties.size(); i++) {
|
|
|
@ -712,6 +681,11 @@ public class AnalyticsArtifactsManagementServiceImpl implements AnalyticsArtifac
|
|
|
|
return eventMappingPropertyDtos;
|
|
|
|
return eventMappingPropertyDtos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Clean Service client in the stub
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param stub Stud that needs to be cleaned
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void cleanup(Stub stub) {
|
|
|
|
private void cleanup(Stub stub) {
|
|
|
|
if (stub != null) {
|
|
|
|
if (stub != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|