use of com.redhat.cloud.policies.app.model.engine.Trigger in project policies-ui-backend by RedHatInsights.
the class AdminService method findOrphans.
@GET
@Path("/verify")
public Response findOrphans() {
Map<String, List<TTT>> orphanedPolicies = new HashMap<>();
List<TTT> orphanedInDB = new ArrayList<>();
List<TTT> orphanedInEngine = new ArrayList<>();
// Find active policies that do not have a trigger in engine
try (Stream<Policy> policies = Policy.streamAll()) {
policies.forEach(p -> {
try {
engine.fetchTrigger(p.id, p.customerid);
} catch (NotFoundException nfe) {
orphanedInDB.add(new TTT(p.customerid, p.id));
}
});
}
orphanedPolicies.put("orphanedInDB", orphanedInDB);
// Find triggers in engine for accounts and check if
// they have an active trigger in the DB
List<String> customersInDb;
try (Stream<Policy> policies = Policy.streamAll()) {
customersInDb = policies.map(p -> p.customerid).distinct().collect(Collectors.toList());
}
customersInDb.forEach(cid -> {
List<Trigger> triggers = engine.findTriggersForCustomer(cid);
triggers.forEach(t -> {
Policy pol = Policy.findById(cid, UUID.fromString(t.id));
if (pol == null) {
orphanedInEngine.add(new TTT(cid, t.id));
}
});
});
orphanedPolicies.put("orphanedInEngine", orphanedInEngine);
return Response.ok().entity(orphanedPolicies).build();
}
use of com.redhat.cloud.policies.app.model.engine.Trigger in project policies-ui-backend by RedHatInsights.
the class TestLifecycleManager method mockEngine.
private void mockEngine() {
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/c49e92c4-dead-beef-9200-245b31933e94/enable").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(500).withReasonPhrase("Internal server error").withHeader("Content-Type", "application/json").withBody("{ \"errorMessage\" : \"something went wrong\" }"));
// -------------------------------
List<Trigger> triggers = new ArrayList<>();
Trigger trigger = new Trigger();
trigger.id = "bd0ee2ec-eec0-44a6-8bb1-29c4179fc21c";
trigger.lifecycle = new ArrayList<>();
Map<String, Object> ev = new HashMap<>();
Calendar cal = getInstance();
cal.set(2020, MAY, 8, 10, 0, 0);
ev.put("status", "ALERT_GENERATE");
ev.put("stime", cal.getTimeInMillis());
trigger.lifecycle.add(ev);
ev = new HashMap<>();
cal.set(2020, MAY, 9, 10, 0, 0);
ev.put("status", "ALERT_GENERATE");
ev.put("stime", cal.getTimeInMillis());
trigger.lifecycle.add(ev);
ev = new HashMap<>();
cal.set(2020, MAY, 10, 10, 0, 0);
ev.put("status", "ALERT_GENERATE");
ev.put("stime", cal.getTimeInMillis());
trigger.lifecycle.add(ev);
triggers.add(trigger);
mockServerClient.when(request().withPath("/hawkular/alerts/triggers").withQueryStringParameter("triggerIds", "bd0ee2ec-eec0-44a6-8bb1-29c4179fc21c").withHeader("Hawkular-Tenant", "1234").withMethod("GET")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody(JsonBody.json(triggers)));
// -------------------------------
FullTrigger ft = new FullTrigger();
ft.trigger.id = "00000000-0000-0000-0000-000000000001";
JsonBody ftBody = JsonBody.json(ft);
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger/00000000-0000-0000-0000-000000000001").withMethod("GET")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody(ftBody));
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/.*/enable").withMethod("PUT")).respond(response().withStatusCode(200));
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/.*/enable").withMethod("DELETE")).respond(response().withStatusCode(200));
// Simulate internal engine issue
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger").withBody(new RegexBody(".*-dead-beef-9200-.*")).withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(500).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
// ------------ status page
mockServerClient.when(request().withPath("/hawkular/alerts/triggers").withQueryStringParameter("triggerIds", "dummy").withHeader("Hawkular-Tenant", "dummy")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("[]"));
mockServerClient.when(request().withPath("/apps")).respond(response().withBody("[]").withHeader("Content-Type", "application/json").withStatusCode(200));
// ------------
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/c49e92c4-dead-beef-9200-245b31933e94").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(500).withHeader("Content-Type", "application/json").withBody("{ \"errorMessage\" : \"something went wrong\" }"));
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/c49e92c4-764c-4163-9200-245b31933e94").withMethod("DELETE").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(404).withHeader("Content-Type", "application/json").withBody("{ \"errorMessage\" : \"does not exist\" }"));
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/.*").withMethod("DELETE").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger/.*").withMethod("PUT").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
}
Aggregations