Search in sources :

Example 61 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class OneOpsEventResource method event.

@POST
@Path("/oneops")
@Consumes(MediaType.APPLICATION_JSON)
@WithTimer
public Response event(Map<String, Object> event) {
    if (executor.isDisabled(EVENT_SOURCE)) {
        log.warn("event ['{}'] disabled", EVENT_SOURCE);
        return Response.ok().build();
    }
    if (event == null || event.isEmpty()) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (cfg.isLogEvents()) {
        auditLog.add(AuditObject.EXTERNAL_EVENT, AuditAction.ACCESS).field("source", EVENT_SOURCE).field("eventId", String.valueOf(event.get("cmsId"))).field("payload", event).log();
    }
    List<OneOpsTriggerProcessor.Result> results = new ArrayList<>();
    processors.forEach(p -> p.process(event, results));
    for (OneOpsTriggerProcessor.Result result : results) {
        Event e = Event.builder().id(String.valueOf(event.get("cmsId"))).name(EVENT_SOURCE).attributes(result.event()).initiator(memo(new EventInitiatorSupplier("author", userManager, result.event()))).build();
        List<PartialProcessKey> processKeys = executor.execute(e, initiatorResolver, result.triggers());
        log.info("event ['{}'] -> done, {} processes started", e.id(), processKeys.size());
    }
    return Response.ok().build();
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ArrayList(java.util.ArrayList) Event(com.walmartlabs.concord.server.events.Event) EventInitiatorSupplier(com.walmartlabs.concord.server.events.EventInitiatorSupplier) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 62 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class EventMarkerDao method get.

@WithTimer
public EventMarker get(String processorName) {
    EventProcessorMarker m = Tables.EVENT_PROCESSOR_MARKER.as("m");
    Long currentEventSeq = txResult(tx -> tx.select(m.EVENT_SEQ).from(m).where(m.PROCESSOR_NAME.eq(processorName)).fetchOne(m.EVENT_SEQ));
    Long maxEventSeq = txResult(tx -> tx.select(max(PROCESS_EVENTS.EVENT_SEQ)).from(PROCESS_EVENTS).fetchOne(Record1::value1));
    return EventMarker.builder().eventSeq(currentEventSeq != null ? currentEventSeq : -1).maxEventSeq(maxEventSeq != null ? maxEventSeq : -1).build();
}
Also used : EventProcessorMarker(com.walmartlabs.concord.server.jooq.tables.EventProcessorMarker) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 63 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class EventMarkerDao method update.

@WithTimer
public void update(DSLContext tx, String processorName, long eventSeq) {
    EventProcessorMarker m = Tables.EVENT_PROCESSOR_MARKER.as("m");
    tx.insertInto(m).columns(m.PROCESSOR_NAME, m.EVENT_SEQ).values(value(processorName), value(eventSeq)).onDuplicateKeyUpdate().set(m.EVENT_SEQ, eventSeq).where(m.PROCESSOR_NAME.eq(processorName)).execute();
}
Also used : EventProcessorMarker(com.walmartlabs.concord.server.jooq.tables.EventProcessorMarker) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 64 with WithTimer

use of com.walmartlabs.concord.server.sdk.metrics.WithTimer in project concord by walmartlabs.

the class SsoRealm method doGetAuthenticationInfo.

@Override
@WithTimer
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    SsoToken t = (SsoToken) token;
    if (t.getUsername() == null) {
        return null;
    }
    UserEntry u = userManager.get(t.getUsername(), t.getDomain(), UserType.LDAP).orElse(null);
    if (u == null) {
        u = userManager.create(t.getUsername(), t.getDomain(), t.getDisplayName(), t.getMail(), UserType.SSO, null);
    }
    // we consider the account active if the authentication was successful
    userManager.enable(u.getId());
    auditLog.add(AuditObject.SYSTEM, AuditAction.ACCESS).userId(u.getId()).field("username", u.getName()).field("userDomain", u.getDomain()).field("realm", REALM_NAME).log();
    UserPrincipal userPrincipal = new UserPrincipal(REALM_NAME, u);
    LdapPrincipal ldapPrincipal = new LdapPrincipal(t.getUsername(), t.getDomain(), t.getNameInNamespace(), t.getUserPrincipalName(), t.getDisplayName(), t.getMail(), t.getGroups(), Collections.singletonMap("mail", t.getMail()));
    return new SimpleAccount(Arrays.asList(userPrincipal, t, ldapPrincipal), t.getCredentials(), getName());
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) LdapPrincipal(com.walmartlabs.concord.server.security.ldap.LdapPrincipal) UserEntry(com.walmartlabs.concord.server.user.UserEntry) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Aggregations

WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)64 ApiOperation (io.swagger.annotations.ApiOperation)32 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)26 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)24 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)22 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)16 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)10 UUID (java.util.UUID)9 ProcessEntry (com.walmartlabs.concord.server.process.ProcessEntry)7 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)6 Inject (javax.inject.Inject)5 Named (javax.inject.Named)5 Payload (com.walmartlabs.concord.server.process.Payload)4 Path (java.nio.file.Path)4 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HttpUtils (com.walmartlabs.concord.server.HttpUtils)3 ProcessFilter (com.walmartlabs.concord.server.process.queue.ProcessFilter)3 UserEntry (com.walmartlabs.concord.server.user.UserEntry)3 IOException (java.io.IOException)3