use of com.redhat.cloud.policies.app.model.Policy in project policies-ui-backend by RedHatInsights.
the class FullTriggerHandlingTest method testSetup.
@Test
void testSetup() {
Policy p = createPolicy();
FullTrigger ft = new FullTrigger(p);
assertFalse(ft.trigger.enabled);
assertEquals("hula", ft.trigger.name);
assertEquals(1, ft.conditions.size());
assertEquals("bla", ft.conditions.get(0).expression);
assertEquals(1, ft.trigger.actions.size());
assertEquals("notification", ft.trigger.actions.iterator().next().actionPlugin);
assertEquals("hula", ft.trigger.name);
assertEquals("some text", ft.trigger.description);
}
use of com.redhat.cloud.policies.app.model.Policy in project policies-ui-backend by RedHatInsights.
the class FullTriggerHandlingTest method createPolicy.
@NotNull
private Policy createPolicy() {
Policy p = new Policy();
p.customerid = "1234";
p.conditions = "bla";
p.actions = "notification";
p.name = "hula";
p.description = "some text";
return p;
}
use of com.redhat.cloud.policies.app.model.Policy in project policies-ui-backend by RedHatInsights.
the class FullTriggerHandlingTest method testActionUpdate1.
@Test
void testActionUpdate1() {
Policy p = createPolicy();
FullTrigger ft = new FullTrigger(p);
p.actions = "notification";
ft.updateFromPolicy(p);
assertEquals(1, ft.trigger.actions.size());
assertEquals("notification", ft.trigger.actions.iterator().next().actionPlugin);
}
use of com.redhat.cloud.policies.app.model.Policy in project policies-ui-backend by RedHatInsights.
the class AdminService method syncToEngine.
@Path("/sync")
@POST
@Transactional
public Response syncToEngine(@QueryParam("token") String token) {
boolean validToken = StuffHolder.getInstance().compareToken(token);
if (!validToken) {
return Response.status(Response.Status.FORBIDDEN).entity("You don't have permission for this").build();
}
final int[] count = { 0 };
try (Stream<Policy> policies = Policy.streamAll()) {
policies.forEach(p -> {
FullTrigger fullTrigger;
try {
fullTrigger = engine.fetchTrigger(p.id, p.customerid);
} catch (NotFoundException nfe) {
fullTrigger = null;
}
if (fullTrigger == null) {
// Engine does not have the trigger
log.info("Trigger " + p.id + " not found, syncing");
FullTrigger ft = new FullTrigger(p);
engine.storeTrigger(ft, false, p.customerid);
log.info(" done");
count[0]++;
} else {
log.info("Trigger " + p.id + " already in engine, skipping");
}
});
}
String s = "Stored " + count[0] + " triggers";
log.info(s);
return Response.ok().entity(new Msg(s)).build();
}
use of com.redhat.cloud.policies.app.model.Policy 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();
}
Aggregations