Skip to content

Commit

Permalink
[TE] Migrate unsubscribed anomaly functions (apache#3766)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayrai authored Jan 31, 2019
1 parent 37fb02b commit 2ce41cf
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,44 @@ public Response migrateApplication(@PathParam("name") String application) throws
}

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/anomaly-function/{id}")
public Response migrateAnomalyFunction(@PathParam("id") long anomalyFunctionId) throws Exception {
return Response.ok(migrateLegacyAnomalyFunction(anomalyFunctionId)).build();
}

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/unsubscribed-anomaly-functions")
public Response migrateAnomalyFunction() throws Exception {
List<AnomalyFunctionDTO> anomalyFunctionDTOs = anomalyFunctionDAO.findAll();
Map<String, String> responseMessage = new HashMap<>();

for (AnomalyFunctionDTO func : anomalyFunctionDTOs) {
if (func.getFunctionName().contains(MIGRATED_TAG)) {
LOGGER.info("[MIG] Function already migrated. Name " + func.getFunctionName());
continue;
}

try {
validateFunction(func);
} catch (ValidationException e) {
LOGGER.info("[MIG] Function failed validation. Name " + func.getFunctionName() + " Error : " + e.getMessage());
continue;
}

try {
migrateLegacyAnomalyFunction(func);
} catch (Exception e) {
// Skip migrating this function and move on to the next
responseMessage.put("Status of function " + func.getId(),
String.format("Failed to migrate function ID %d with name %s due to %s", func.getId(),
func.getFunctionName(), e.getMessage()));
}
}

return Response.ok(responseMessage).build();
}
}

0 comments on commit 2ce41cf

Please sign in to comment.