Updates to method comments and swagger documentation

feature/appm-store/pbac
Yohan Avishke 5 years ago
parent 1c2d1f52a0
commit 9d7ad19f57

@ -138,21 +138,15 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), 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( @ApiResponse(
code = 400, code = 400,
message = "Bad Request."), message = "Bad Request. \n The resource to add already exists."),
@ApiResponse(
code = 404,
message = "Not Found. \n The resource to edit not available."),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ -202,21 +196,12 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), 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( @ApiResponse(
code = 400, code = 400,
message = "Bad Request."), message = "Bad Request. \n The payload is invalid."),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ -235,7 +220,7 @@ public interface AnalyticsArtifactsManagementService {
@Valid EventStream stream); @Valid EventStream stream);
@DELETE @DELETE
@Path("/stream/{name}/{version}/delete") @Path("/stream/{name}/{version}")
@ApiOperation( @ApiOperation(
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Delete the Stream with id as {name}:{version}", value = "Delete the Stream with id as {name}:{version}",
@ -257,25 +242,15 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), 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( @ApiResponse(
code = 400, code = 404,
message = "Bad Request."), message = "Not Found. \n The resource to delete not available."),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n" + message = "Not Acceptable. \n The requested media type is not supported."),
"The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \nServer error occurred while " + message = "Internal Server Error. \nServer error occurred while " +
@ -320,22 +295,9 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body."), 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( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ -385,22 +347,13 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body."), 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( @ApiResponse(
code = 400, code = 400,
message = message =
"Bad Request."), "Bad Request. \n The payload is invalid."),
@ApiResponse( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ -419,7 +372,7 @@ public interface AnalyticsArtifactsManagementService {
@Valid Adapter receiver); @Valid Adapter receiver);
@DELETE @DELETE
@Path("/receiver/{name}/delete") @Path("/receiver/{name}")
@ApiOperation( @ApiOperation(
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Delete a Receiver with the given name", value = "Delete a Receiver with the given name",
@ -442,28 +395,12 @@ public interface AnalyticsArtifactsManagementService {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body" 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( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n" + message = "Not Acceptable. \n The requested media type is not supported."
"The requested media type is not supported."
), ),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
@ -504,22 +441,9 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body."), 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( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ -569,16 +493,7 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body."), 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( @ApiResponse(
@ -603,7 +518,7 @@ public interface AnalyticsArtifactsManagementService {
@Valid Adapter publisher); @Valid Adapter publisher);
@DELETE @DELETE
@Path("/publisher/{name}/delete") @Path("/publisher/{name}")
@ApiOperation( @ApiOperation(
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Delete a Publisher with the given name", value = "Delete a Publisher with the given name",
@ -625,25 +540,12 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), 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( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n" + message = "Not Acceptable. \n The requested media type is not supported."),
"The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while " + message = "Internal Server Error. \n Server error occurred while " +
@ -659,6 +561,7 @@ public interface AnalyticsArtifactsManagementService {
@PathParam("name") String name); @PathParam("name") String name);
@POST @POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/siddhi-script/{name}") @Path("/siddhi-script/{name}")
@ApiOperation( @ApiOperation(
httpMethod = "POST", httpMethod = "POST",
@ -681,22 +584,9 @@ public interface AnalyticsArtifactsManagementService {
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body."), 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( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ -723,7 +613,7 @@ public interface AnalyticsArtifactsManagementService {
@Valid SiddhiExecutionPlan plan); @Valid SiddhiExecutionPlan plan);
@DELETE @DELETE
@Path("/siddhi-script/{name}/delete") @Path("/siddhi-script/{name}")
@ApiOperation( @ApiOperation(
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Delete an already deployed Siddhi script", value = "Delete an already deployed Siddhi script",
@ -742,29 +632,16 @@ public interface AnalyticsArtifactsManagementService {
value = { value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully delete the Siddhi script Artifact.", message = "OK. \n Successfully deleted the Siddhi script Artifact.",
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), 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( @ApiResponse(
code = 406, code = 406,
message = "Not Acceptable.\n" + message = "Not Acceptable. \n The requested media type is not supported."),
"The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error.\n Server error occurred while " + message = "Internal Server Error.\n Server error occurred while " +

@ -82,10 +82,12 @@ public class AnalyticsArtifactsManagementServiceImpl
try { try {
String streamDefinition = stream.getDefinition(); String streamDefinition = stream.getDefinition();
if (deployStream(id, streamDefinition, isEdited)) { if (deployStream(id, streamDefinition, isEdited)) {
return Response.ok().build(); return Response.ok().entity("Stream artifact of id " + id +
" successfully deployed").build();
} else { } else {
String errMsg = "Failed to create the Stream artifact of id: " + id + String errMsg = "Failed to create the Stream artifact of id: " + id +
" for tenant domain: " + tenantDomain; " for tenant domain: " + tenantDomain;
log.error(errMsg);
return Response.serverError().entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} }
} catch (ArtifactAlreadyExistsException e) { } catch (ArtifactAlreadyExistsException e) {
@ -124,13 +126,13 @@ public class AnalyticsArtifactsManagementServiceImpl
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
validateStreamProperties(stream); validateStreamProperties(stream);
String name = stream.getName(); String id = stream.getName() + ":" + stream.getVersion();
String version = stream.getVersion();
if (deployStream(stream)) { if (deployStream(stream)) {
return Response.ok().build(); return Response.ok().entity("Stream artifact of id " + id +
" successfully deployed").build();
} else { } else {
String errMsg = String.format("Failed to create the Stream artifact of id: %s:%s " + String errMsg = "Failed to create the Stream artifact of id: " + id +
"for tenant domain: %s", name, version, tenantDomain); "for tenant domain: " + tenantDomain;
log.error(errMsg); log.error(errMsg);
return Response.serverError().entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} }
@ -159,22 +161,23 @@ public class AnalyticsArtifactsManagementServiceImpl
@Override @Override
@DELETE @DELETE
@Path("/stream/{name}/{version}/delete") @Path("/stream/{name}/{version}")
public Response deleteStream(@PathParam("name") String name, public Response deleteStream(@PathParam("name") String name,
@PathParam("version") String version) { @PathParam("version") String version) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String id = name + ":" + version;
try { try {
if (undeployStream(name, version)) { if (undeployStream(name, version)) {
return Response.ok().build(); return Response.ok().entity("Stream artifact of id " + id +
" successfully deleted").build();
} else { } else {
String errMsg = String.format("Failed to undeploy the Stream artifact of id: %s:%s " + String errMsg = "Failed to undeploy the Stream artifact of id: " + id +
"for tenant domain: %s", name, version, tenantDomain); "for tenant domain: " + tenantDomain;
log.error(errMsg); log.error(errMsg);
return Response.serverError().entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
String errMsg = String.format("Failed to undeploy Stream with id %s:%s for tenant %s" String errMsg = "Failed to undeploy Stream with id " + id + "for tenant " + tenantDomain;
, name, version, tenantDomain);
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
} catch (AxisFault e) { } catch (AxisFault e) {
@ -199,11 +202,16 @@ public class AnalyticsArtifactsManagementServiceImpl
@Override @Override
@POST @POST
@Path("/receiver/{name}") @Path("/receiver/{name}")
/*
Ideally this method should validate the existence of receiver before creating or editing. But
EventReceiverAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deployEventReceiverAsString(@PathParam("name") String name, public Response deployEventReceiverAsString(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited, @QueryParam("isEdited") boolean isEdited,
@Valid Adapter receiver) { @Valid Adapter receiver) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
EventReceiverAdminServiceStub eventReceiverAdminServiceStub; EventReceiverAdminServiceStub eventReceiverAdminServiceStub = null;
try { try {
String receiverDefinition = receiver.getDefinition(); String receiverDefinition = receiver.getDefinition();
eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub(); eventReceiverAdminServiceStub = DeviceMgtAPIUtils.getEventReceiverAdminServiceStub();
@ -212,29 +220,37 @@ public class AnalyticsArtifactsManagementServiceImpl
} else { } else {
eventReceiverAdminServiceStub.editActiveEventReceiverConfiguration(receiverDefinition, name); eventReceiverAdminServiceStub.editActiveEventReceiverConfiguration(receiverDefinition, name);
} }
return Response.ok().build(); return Response.ok().entity("Receiver artifact of name " + name +
" successfully deployed").build();
} catch (AxisFault e) { } catch (AxisFault e) {
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain; String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} catch (RemoteException e) { } catch (RemoteException e) {
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain; String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} catch (JWTClientException e) { } catch (JWTClientException e) {
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain; String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain; String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} finally {
cleanup(eventReceiverAdminServiceStub);
} }
} }
@Override @Override
@POST @POST
@Path("/receiver") @Path("/receiver")
/*
Ideally this method should validate the existence of receiver before creating or editing. But
EventReceiverAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deployEventReceiverAsDto(@Valid Adapter receiver) { public Response deployEventReceiverAsDto(@Valid Adapter receiver) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
@ -245,7 +261,8 @@ public class AnalyticsArtifactsManagementServiceImpl
validateAdapterMapping(adapterConfiguration.getAdapterMappingConfiguration()); validateAdapterMapping(adapterConfiguration.getAdapterMappingConfiguration());
} }
deployReceiver(receiver, customMapping, adapterConfiguration); deployReceiver(receiver, customMapping, adapterConfiguration);
return Response.ok().build(); return Response.ok().entity("Receiver artifact of name " + receiver.getAdapterName()
+ " successfully deployed").build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String errMsg = "Failed to deploy receiver due to invalid payload"; String errMsg = "Failed to deploy receiver due to invalid payload";
log.error(errMsg, e); log.error(errMsg, e);
@ -271,15 +288,21 @@ public class AnalyticsArtifactsManagementServiceImpl
@Override @Override
@DELETE @DELETE
@Path("/receiver/{name}/delete") @Path("/receiver/{name}")
/*
Ideally this method should validate the existence of receiver before deleting. But
EventReceiverAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deleteReceiver(@PathParam("name") String name) { public Response deleteReceiver(@PathParam("name") String name) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
if (undeployAdapter(name, "Receiver")) { if (undeployAdapter(name, "Receiver")) {
return Response.ok().build(); return Response.ok().entity("Receiver artifact of name " + name +
" successfully deleted").build();
} else { } else {
String errMsg = String.format("Failed to undeploy the Receiver artifact of name: %s" + String errMsg = "Failed to undeploy the Receiver artifact of name: " + name +
"for tenant domain: %s", name, tenantDomain); "for tenant domain: " + tenantDomain;
log.error(errMsg); log.error(errMsg);
return Response.serverError().entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} }
@ -305,11 +328,16 @@ public class AnalyticsArtifactsManagementServiceImpl
@Override @Override
@POST @POST
@Path("/publisher/{name}") @Path("/publisher/{name}")
/*
Ideally this method should validate the existence of publisher before creating or editing. But
EventPublisherAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deployEventPublisherAsString(@PathParam("name") String name, public Response deployEventPublisherAsString(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited, @QueryParam("isEdited") boolean isEdited,
@Valid Adapter publisher) { @Valid Adapter publisher) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
EventPublisherAdminServiceStub eventPublisherAdminServiceStub; EventPublisherAdminServiceStub eventPublisherAdminServiceStub = null;
try { try {
String publisherDefinition = publisher.getDefinition(); String publisherDefinition = publisher.getDefinition();
eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub(); eventPublisherAdminServiceStub = DeviceMgtAPIUtils.getEventPublisherAdminServiceStub();
@ -318,29 +346,37 @@ public class AnalyticsArtifactsManagementServiceImpl
} else { } else {
eventPublisherAdminServiceStub.editActiveEventPublisherConfiguration(publisherDefinition, name); eventPublisherAdminServiceStub.editActiveEventPublisherConfiguration(publisherDefinition, name);
} }
return Response.ok().build(); return Response.ok().entity("Publisher artifact of name " + name +
" successfully deployed").build();
} catch (AxisFault e) { } catch (AxisFault e) {
String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain; String errMsg = "Failed to create event definitions for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} catch (RemoteException e) { } catch (RemoteException e) {
String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain; String errMsg = "Failed to connect with the remote services for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} catch (JWTClientException e) { } catch (JWTClientException e) {
String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain; String errMsg = "Failed to generate jwt token for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain; String errMsg = "Failed to connect with the user store for tenantDomain: " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} finally {
cleanup(eventPublisherAdminServiceStub);
} }
} }
@Override @Override
@POST @POST
@Path("/publisher") @Path("/publisher")
/*
Ideally this method should validate the existence of publisher before creating or editing. But
EventPublisherAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deployEventPublisherAsDto(@Valid Adapter publisher) { public Response deployEventPublisherAsDto(@Valid Adapter publisher) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
AdapterConfiguration adapterConfiguration = publisher.getAdapterConfiguration(); AdapterConfiguration adapterConfiguration = publisher.getAdapterConfiguration();
@ -351,7 +387,8 @@ public class AnalyticsArtifactsManagementServiceImpl
validateAdapterMapping(adapterConfiguration.getAdapterMappingConfiguration()); validateAdapterMapping(adapterConfiguration.getAdapterMappingConfiguration());
} }
deployPublisher(publisher, customMapping, adapterConfiguration); deployPublisher(publisher, customMapping, adapterConfiguration);
return Response.ok().build(); return Response.ok().entity("Publisher artifact of name " + publisher.getAdapterName()
+ " successfully deployed").build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String errMsg = "Failed to deploy publisher due to invalid payload"; String errMsg = "Failed to deploy publisher due to invalid payload";
log.error(errMsg, e); log.error(errMsg, e);
@ -377,15 +414,21 @@ public class AnalyticsArtifactsManagementServiceImpl
@Override @Override
@DELETE @DELETE
@Path("/publisher/{name}/delete") @Path("/publisher/{name}")
/*
Ideally this method should validate the existence of publisher before deleting. But
EventPublisherAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deletePublisher(@PathParam("name") String name) { public Response deletePublisher(@PathParam("name") String name) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
if (undeployAdapter(name, "Publisher")) { if (undeployAdapter(name, "Publisher")) {
return Response.ok().build(); return Response.ok().entity("Publisher artifact of name " + name +
" successfully deleted").build();
} else { } else {
String errMsg = String.format("Failed to undeploy the Publisher artifact of name: %s" + String errMsg = "Failed to undeploy the Publisher artifact of name: " + name +
"for tenant domain: %s", name, tenantDomain); "for tenant domain: " + tenantDomain;
log.error(errMsg); log.error(errMsg);
return Response.serverError().entity(errMsg).build(); return Response.serverError().entity(errMsg).build();
} }
@ -411,13 +454,19 @@ public class AnalyticsArtifactsManagementServiceImpl
@Override @Override
@POST @POST
@Path("/siddhi-script/{name}") @Path("/siddhi-script/{name}")
/*
Ideally this method should validate the existence of Siddhi script before creating or editing. But
EventProcessorAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deploySiddhiExecutableScript(@PathParam("name") String name, public Response deploySiddhiExecutableScript(@PathParam("name") String name,
@QueryParam("isEdited") boolean isEdited, @QueryParam("isEdited") boolean isEdited,
@Valid SiddhiExecutionPlan plan) { @Valid SiddhiExecutionPlan plan) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
deploySiddhiExecutionPlan(name, isEdited, plan.getDefinition()); deploySiddhiExecutionPlan(name, isEdited, plan.getDefinition());
return Response.ok().build(); return Response.ok().entity("Siddhi script artifact of name " + name +
" successfully deleted").build();
} catch (InvalidExecutionPlanException e) { } catch (InvalidExecutionPlanException e) {
String errMsg = "Failed to deploy siddhi script due to invalid payload"; String errMsg = "Failed to deploy siddhi script due to invalid payload";
log.error(errMsg, e); log.error(errMsg, e);
@ -443,12 +492,18 @@ public class AnalyticsArtifactsManagementServiceImpl
@Override @Override
@DELETE @DELETE
@Path("/siddhi-script/{name}/delete") @Path("/siddhi-script/{name}")
/*
Ideally this method should validate the existence of Siddhi script before deleting. But
EventProcessorAdminServiceStub haven't implemented the methods to support these validations.
Therefore a common server error response is returned by catching Axis Fault
*/
public Response deleteSiddhiScript(@PathParam("name") String name) { public Response deleteSiddhiScript(@PathParam("name") String name) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
try { try {
undeploySiddhiScript(name); undeploySiddhiScript(name);
return Response.ok().build(); return Response.ok().entity("Publisher artifact of name " + name +
" successfully deleted").build();
} catch (AxisFault e) { } catch (AxisFault e) {
String errMsg = "Failed to delete event definitions for tenant " + tenantDomain; String errMsg = "Failed to delete event definitions for tenant " + tenantDomain;
log.error(errMsg, e); log.error(errMsg, e);
@ -469,17 +524,24 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Deploy Stream by passing a string to a stub * Deploy Stream by passing data as string to a stub
* *
* @param streamId Stream name:version * @param streamId Stream name:version
* @param streamDefinition Stream that should be deployed * @param streamDefinition Stream that should be deployed
* @param isEdited Create a new stream or edit an existing one * @param isEdited Create a new stream or edit an existing one
* @return True if stream successfully created and false if not * @return True if stream successfully created and false if not
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventStreamAdminServiceStub and if communication
* @throws JWTClientException Exception that may occur during connecting to client store * gets interfered
* @throws NotFoundException Exception that may occure if stream doesn't exist while editing * @throws UserStoreException Exception that may occur while getting user data from
* @throws ArtifactAlreadyExistsException Exception that may occure if stream exist while creating * the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventStreamAdminServiceStub
* instance, as a jwt based token client is used to generate a token
* for the tenant in the process
* @throws NotFoundException Exception that may occur if stream doesn't exist,
* when the method is called with isEdited flag as True
* @throws ArtifactAlreadyExistsException Exception that may occur if stream does exist,
* when the method is called with isEdited flag as False
*/ */
private boolean deployStream(String streamId, String streamDefinition, boolean isEdited) private boolean deployStream(String streamId, String streamDefinition, boolean isEdited)
throws UserStoreException, JWTClientException, RemoteException, NotFoundException, throws UserStoreException, JWTClientException, RemoteException, NotFoundException,
@ -502,14 +564,18 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Deploy Stream by passing a DTO object to a stub * Deploy Stream by passing data as a DTO object to a stub
* *
* @param stream Stream definition * @param stream Stream definition
* @return True if stream successfully created and false if not * @return True if stream successfully created and false if not
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventStreamAdminServiceStub and if communication
* @throws JWTClientException Exception that may occur during connecting to client store * gets interfered
* @throws NotFoundException Exception that may occure if stream doesn't exist while editing * @throws UserStoreException Exception that may occur while getting user data from
* the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventStreamAdminServiceStub
* instance, as a jwt based token client is used to generate a token
* for the tenant in the process
*/ */
private boolean deployStream(EventStream stream) private boolean deployStream(EventStream stream)
throws RemoteException, UserStoreException, JWTClientException { throws RemoteException, UserStoreException, JWTClientException {
@ -553,10 +619,16 @@ public class AnalyticsArtifactsManagementServiceImpl
* @param name Stream name * @param name Stream name
* @param version Stream version * @param version Stream version
* @return True if stream successfully created and false if not * @return True if stream successfully created and false if not
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventStreamAdminServiceStub and if communication
* @throws JWTClientException Exception that may occur during connecting to client store * gets interfered
* @throws NotFoundException Exception that may occure if stream doesn't exist * @throws UserStoreException Exception that may occur while getting user data from
* the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventStreamAdminServiceStub
* instance, as a jwt based token client is used to generate a token
* for the tenant in the process
* @throws NotFoundException Exception that may occur if stream doesn't exist,
* when the method is called with isEdited flag as True
*/ */
private boolean undeployStream(String name, String version) private boolean undeployStream(String name, String version)
throws RemoteException, UserStoreException, JWTClientException, NotFoundException { throws RemoteException, UserStoreException, JWTClientException, NotFoundException {
@ -578,14 +650,19 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Set data to a receiver dto and deploy dto through a stub * Deploy Receiver by passing data as a DTO object to a stub
* *
* @param receiver Event Receiver adapter * @param receiver Event Receiver adapter
* @param customMapping Is Receiver mapped * @param customMapping Is Receiver mapped
* @param adapterConfiguration Adapter property and mapping configuration * @param adapterConfiguration Adapter property and mapping configuration
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventReceiverAdminServiceStub and if communication
* @throws JWTClientException Exception that may occur during connecting to client store * gets interfered
* @throws UserStoreException Exception that may occur while getting user data from
* the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventReceiverAdminServiceStub
* instance, as a jwt based token client is used to generate a token
* for the tenant in the process
*/ */
private void deployReceiver(Adapter receiver, boolean customMapping, private void deployReceiver(Adapter receiver, boolean customMapping,
AdapterConfiguration adapterConfiguration) AdapterConfiguration adapterConfiguration)
@ -660,14 +737,16 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* To deploy receiver if custom mapping is false * Deploy Receiver by passing data as a DTO object to a stub when custom mapping is False
* *
* @param receiverName Name of the receiver * @param receiverName Name of the receiver
* @param eventStreamWithVersion Attached event stream of the receiver * @param eventStreamWithVersion Attached event stream of the receiver
* @param adapterType Adapter type name * @param adapterType Adapter type name
* @param eventReceiverAdminServiceStub Stub to deploy receiver * @param eventReceiverAdminServiceStub Stub to deploy receiver
* @param basicInputAdapterPropertyDtos DTO to attach receiver data * @param basicInputAdapterPropertyDtos DTO to attach receiver data
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* through EventReceiverAdminServiceStub and if communication
* gets interfered
*/ */
private void deployReceiverWithoutMapping(String receiverName, String eventStreamWithVersion private void deployReceiverWithoutMapping(String receiverName, String eventStreamWithVersion
, String adapterType, EventReceiverAdminServiceStub eventReceiverAdminServiceStub , String adapterType, EventReceiverAdminServiceStub eventReceiverAdminServiceStub
@ -694,14 +773,19 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Set data to a publisher dto and deploy dto through a stub * Deploy Publisher by passing data as a DTO object to a stub
* *
* @param publisher Event Publisher adapter * @param publisher Event Publisher adapter
* @param customMapping Is Publisher mapped * @param customMapping Is Publisher mapped
* @param adapterConfiguration Publisher property and mapping configuration * @param adapterConfiguration Publisher property and mapping configuration
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventPublisherAdminServiceStub and if communication
* @throws JWTClientException Exception that may occur during connecting to client store * gets interfered
* @throws UserStoreException Exception that may occur while getting user data from
* the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventPublisherAdminServiceStub
* instance, as a jwt based token client is used to generate a token
* for the tenant in the process
*/ */
private void deployPublisher(Adapter publisher, boolean customMapping, private void deployPublisher(Adapter publisher, boolean customMapping,
AdapterConfiguration adapterConfiguration) AdapterConfiguration adapterConfiguration)
@ -788,14 +872,16 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* To deploy publisher if custom mapping is false * Deploy Publisher by passing data as a DTO object to a stub when custom mapping is False
* *
* @param publisherName Name of the publisher * @param publisherName Name of the publisher
* @param eventStreamWithVersion Attached event stream of the publisher * @param eventStreamWithVersion Attached event stream of the publisher
* @param adapterType Adapter type name * @param adapterType Adapter type name
* @param eventPublisherAdminServiceStub Stub to deploy publisher * @param eventPublisherAdminServiceStub Stub to deploy publisher
* @param basicOutputAdapterPropertyDtos DTO to attach publisher data * @param basicOutputAdapterPropertyDtos DTO to attach publisher data
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* through EventPublisherAdminServiceStub and if communication
* gets interfered
*/ */
private void deployPublisherWithoutMapping(String publisherName, String eventStreamWithVersion private void deployPublisherWithoutMapping(String publisherName, String eventStreamWithVersion
, String adapterType, EventPublisherAdminServiceStub eventPublisherAdminServiceStub , String adapterType, EventPublisherAdminServiceStub eventPublisherAdminServiceStub
@ -831,12 +917,19 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Undeploy an active publisher or a receiver artifact
*
* @param name Adapter name * @param name Adapter name
* @param type Adapter type(Receiver or Publisher) * @param type Adapter type(Receiver or Publisher)
* @return True if Adapter successfully created and false if not * @return True if Adapter successfully created and false if not
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventReceiverAdminServiceStub or EventPublisherAdminServiceStub
* @throws JWTClientException Exception that may occur during connecting to client store * and if communication gets interfered
* @throws UserStoreException Exception that may occur while getting user data from
* the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventReceiverAdminServiceStub or
* EventPublisherAdminServiceStub instance, as a jwt based token client
* is used to generate a token for the tenant in the process
*/ */
private boolean undeployAdapter(String name, String type) private boolean undeployAdapter(String name, String type)
throws RemoteException, UserStoreException, JWTClientException { throws RemoteException, UserStoreException, JWTClientException {
@ -862,15 +955,21 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Publish a siddhi execution plan using a stub * Deploy Siddhi script by passing data as a DTO object to a stub
* *
* @param name Plan name * @param name Plan name
* @param isEdited Is plan edited * @param isEdited Is plan edited
* @param plan Plan data * @param plan Plan data
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventProcessorAdminServiceStub and if communication
* @throws JWTClientException Exception that may occur during connecting to client store * gets interfered
* @throws InvalidExecutionPlanException Exception that may occur if execution plan validation fails * @throws UserStoreException Exception that may occur while getting user data from
* the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventProcessorAdminServiceStub
* instance, as a jwt based token client is used to generate a
* token for the tenant in the process
* @throws InvalidExecutionPlanException Exception that may occur if Siddhi script validation fails
* due to having errors in the code
*/ */
private void deploySiddhiExecutionPlan(String name, boolean isEdited, String plan) private void deploySiddhiExecutionPlan(String name, boolean isEdited, String plan)
throws RemoteException, UserStoreException, JWTClientException, throws RemoteException, UserStoreException, JWTClientException,
@ -894,12 +993,17 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Undeploy a Siddhi artifact * Undeploy an active Siddhi artifact
* *
* @param name Siddhi script name * @param name Siddhi script name
* @throws RemoteException Exception that may occur during a remote method call * @throws RemoteException Exception that may occur when a SOAP request is made
* @throws UserStoreException Exception that may occur during JWT token generation * through EventProcessorAdminServiceStub and if communication
* @throws JWTClientException Exception that may occur during connecting to client store * gets interfered
* @throws UserStoreException Exception that may occur while getting user data from
* the client store for the specific tenant
* @throws JWTClientException Exception that may occur during creating a EventProcessorAdminServiceStub
* instance, as a jwt based token client is used to generate a
* token for the tenant in the process
*/ */
private void undeploySiddhiScript(String name) private void undeploySiddhiScript(String name)
throws RemoteException, UserStoreException, JWTClientException { throws RemoteException, UserStoreException, JWTClientException {
@ -913,16 +1017,23 @@ public class AnalyticsArtifactsManagementServiceImpl
} }
/** /**
* Validate if stream exists for update or if stream can be created
*
* @param streamId Stream name:version * @param streamId Stream name:version
* @param eventStreamAdminServiceStub stub used to mange Stream artifacts * @param eventStreamAdminServiceStub stub used to mange Stream artifacts
* @param isEdited Create a new stream or edit an existing one * @param isEdited Create a new stream or edit an existing one
* @throws ArtifactAlreadyExistsException Exception that may occur if stream exist while creating * @throws ArtifactAlreadyExistsException Will be thrown if stream with same id exists when isEdited
* @throws RemoteException Exception that may occur during a remote method call * is False
* @throws NotFoundException Will be thrown if stream with same id doesn't exist when
* isEdited is True
* @throws RemoteException Exception that may occur when a SOAP request is made
* through EventProcessorAdminServiceStub and if communication
* gets interfered while getting the stream definition
*/ */
private void validateStreamId(String streamId, private void validateStreamId(String streamId,
EventStreamAdminServiceStub eventStreamAdminServiceStub, EventStreamAdminServiceStub eventStreamAdminServiceStub,
boolean isEdited) boolean isEdited)
throws ArtifactAlreadyExistsException, RemoteException { throws ArtifactAlreadyExistsException, RemoteException, NotFoundException {
EventStreamDefinitionDto eventStreamDefinitionDto = eventStreamAdminServiceStub EventStreamDefinitionDto eventStreamDefinitionDto = eventStreamAdminServiceStub
.getStreamDefinitionDto(streamId); .getStreamDefinitionDto(streamId);
if (isEdited) { if (isEdited) {
@ -946,7 +1057,7 @@ public class AnalyticsArtifactsManagementServiceImpl
* Validate stream properties * Validate stream properties
* *
* @param stream EventStream object * @param stream EventStream object
* @throws BadRequestException Exception that may occur if property attributes invalid * @throws BadRequestException Will be thrown if Stream has invalid properties
*/ */
private void validateStreamProperties(EventStream stream) throws BadRequestException { private void validateStreamProperties(EventStream stream) throws BadRequestException {
if ((stream.getMetaData() == null || stream.getMetaData().isEmpty()) && if ((stream.getMetaData() == null || stream.getMetaData().isEmpty()) &&
@ -963,7 +1074,7 @@ public class AnalyticsArtifactsManagementServiceImpl
* Validate adapter payload attributes * Validate adapter payload attributes
* *
* @param adapterProperties Adapter payload attributes * @param adapterProperties Adapter payload attributes
* @throws BadRequestException Exception that may occur if adapter properties invalid * @throws BadRequestException Will be thrown if Stream has invalid properties
*/ */
private void validateAdapterProperties(List<AdapterProperty> adapterProperties) private void validateAdapterProperties(List<AdapterProperty> adapterProperties)
throws BadRequestException { throws BadRequestException {
@ -983,7 +1094,7 @@ public class AnalyticsArtifactsManagementServiceImpl
* - else continue * - else continue
* *
* @param adapterMappingConfiguration Adapter mapping attributes * @param adapterMappingConfiguration Adapter mapping attributes
* @throws BadRequestException Exception that may occur if adapter mapping properties invalid * @throws BadRequestException Will be thrown if Stream has invalid properties
*/ */
private void validateAdapterMapping(AdapterMappingConfiguration adapterMappingConfiguration) private void validateAdapterMapping(AdapterMappingConfiguration adapterMappingConfiguration)
throws BadRequestException { throws BadRequestException {

Loading…
Cancel
Save