Search in sources :

Example 51 with WithTimer

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

the class ProcessEventResource method event.

/**
 * Register a process event.
 */
@POST
@ApiOperation(value = "Register a process event", authorizations = { @Authorization("session_key"), @Authorization("api_key") })
@Path("/{processInstanceId}/event")
@Consumes(MediaType.APPLICATION_JSON)
@WithTimer
public void event(@ApiParam @PathParam("processInstanceId") UUID processInstanceId, @ApiParam ProcessEventRequest req) {
    ProcessKey processKey = assertProcessKey(processInstanceId);
    NewProcessEvent e = NewProcessEvent.builder().processKey(processKey).eventType(req.getEventType()).eventDate(req.getEventDate()).data(req.getData()).build();
    eventManager.event(Collections.singletonList(e));
}
Also used : ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 52 with WithTimer

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

the class UserActivityResource method activity.

@GET
@Path("/activity")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public UserActivityResponse activity(@QueryParam("maxProjectsPerOrg") @DefaultValue("5") int maxProjectsPerOrg, @QueryParam("maxOwnProcesses") @DefaultValue("5") int maxOwnProcesses) {
    UserPrincipal user = UserPrincipal.assertCurrent();
    Set<UUID> orgIds = userDao.getOrgIds(user.getId());
    OffsetDateTime t = startOfDay();
    Map<String, List<ProjectProcesses>> orgProcesses = processStatsDao.processByOrgs(maxProjectsPerOrg, orgIds, ORG_VISIBLE_STATUSES, t);
    Map<String, Integer> stats = processStatsDao.getCountByStatuses(orgIds, t, user.getId());
    ProcessFilter filter = ProcessFilter.builder().initiator(user.getUsername()).orgIds(orgIds).includeWithoutProject(true).limit(maxOwnProcesses).build();
    List<ProcessEntry> lastProcesses = processDao.list(filter);
    return new UserActivityResponse(stats, orgProcesses, lastProcesses);
}
Also used : ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) UserPrincipal(com.walmartlabs.concord.server.security.UserPrincipal) OffsetDateTime(java.time.OffsetDateTime) ProcessFilter(com.walmartlabs.concord.server.process.queue.ProcessFilter) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 53 with WithTimer

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

the class GithubEventResource method onEvent.

@POST
@ApiOperation("Handles GitHub repository level events")
@Path("/webhook")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
@WithTimer
public String onEvent(@ApiParam Map<String, Object> data, @HeaderParam("X-GitHub-Delivery") String deliveryId, @HeaderParam("X-GitHub-Event") String eventName, @Context UriInfo uriInfo) {
    log.info("onEvent ['{}', '{}'] -> processing...", deliveryId, eventName);
    if ("ping".equalsIgnoreCase(eventName)) {
        return "ok";
    }
    if (executor.isDisabled(eventName)) {
        log.warn("event ['{}', '{}'] -> disabled", deliveryId, eventName);
        return "ok";
    }
    if (githubCfg.isLogEvents()) {
        auditLog.add(AuditObject.EXTERNAL_EVENT, AuditAction.ACCESS).field("source", EVENT_SOURCE).field("eventId", deliveryId).field("githubEvent", eventName).field("payload", data).log();
    }
    Payload payload = Payload.from(eventName, data);
    if (payload == null) {
        log.warn("event ['{}', '{}'] -> can't parse payload", deliveryId, eventName);
        return "ok";
    }
    List<GithubTriggerProcessor.Result> results = new ArrayList<>();
    processors.forEach(p -> p.process(eventName, payload, uriInfo, results));
    Supplier<UserEntry> initiatorSupplier = memo(new GithubEventInitiatorSupplier(userManager, ldapManager, payload));
    int startedProcesses = 0;
    for (GithubTriggerProcessor.Result r : results) {
        Event e = Event.builder().id(deliveryId).name(EVENT_SOURCE).attributes(r.event()).initiator(initiatorSupplier).build();
        List<PartialProcessKey> processes = executor.execute(e, r.triggers(), initiatorResolver, (t, cfg) -> {
            // if `useEventCommitId` is true then the process is forced to use the specified commit ID
            String commitId = MapUtils.getString(r.event(), COMMIT_ID_KEY);
            if (commitId != null && TriggerUtils.isUseEventCommitId(t)) {
                cfg.put(Constants.Request.REPO_COMMIT_ID, commitId);
                cfg.put(Constants.Request.REPO_BRANCH_OR_TAG, payload.getHead());
            }
            return cfg;
        }, new GithubExclusiveParamsResolver(payload));
        startedProcesses += processes.size();
    }
    startedProcessesPerEvent.update(startedProcesses);
    log.info("onEvent ['{}', '{}'] -> done, started process count: {}", deliveryId, eventName, startedProcesses);
    return "ok";
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) GithubTriggerProcessor(com.walmartlabs.concord.server.events.github.GithubTriggerProcessor) Payload(com.walmartlabs.concord.server.events.github.Payload) UserEntry(com.walmartlabs.concord.server.user.UserEntry) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 54 with WithTimer

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

the class ProjectProcessResource method list.

@GET
@ApiOperation("List processes for the specified project")
@Path("/{orgName}/project/{projectName}/process")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
@Deprecated
public List<ProcessEntry> list(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("projectName") @ConcordKey String projectName, @ApiParam @QueryParam("status") ProcessStatus processStatus, @ApiParam @QueryParam("afterCreatedAt") OffsetDateTimeParam afterCreatedAt, @ApiParam @QueryParam("beforeCreatedAt") OffsetDateTimeParam beforeCreatedAt, @ApiParam @QueryParam("limit") @DefaultValue(DEFAULT_LIST_LIMIT) int limit, @ApiParam @QueryParam("offset") @DefaultValue("0") int offset) {
    OrganizationEntry org = orgManager.assertAccess(orgName, false);
    UUID projectId = projectDao.getId(org.getId(), projectName);
    if (projectId == null) {
        throw new ConcordApplicationException("Project not found: " + projectName, Response.Status.NOT_FOUND);
    }
    ProcessFilter filter = ProcessFilter.builder().projectId(projectId).status(processStatus).afterCreatedAt(unwrap(afterCreatedAt)).beforeCreatedAt(unwrap(beforeCreatedAt)).limit(limit).offset(offset).build();
    return queueDao.list(filter);
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessFilter(com.walmartlabs.concord.server.process.queue.ProcessFilter) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 55 with WithTimer

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

the class ConsoleService method isRepositoryExists.

@GET
@Path("/org/{orgName}/project/{projectName}/repo/{repoName}/exists")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public boolean isRepositoryExists(@PathParam("orgName") @ConcordKey String orgName, @PathParam("projectName") @ConcordKey String projectName, @PathParam("repoName") String repoName) {
    try {
        OrganizationEntry org = orgManager.assertAccess(orgName, true);
        UUID projectId = projectDao.getId(org.getId(), projectName);
        if (projectId == null) {
            throw new ConcordApplicationException("Project not found: " + projectName, Status.BAD_REQUEST);
        }
        return repositoryDao.getId(projectId, repoName) != null;
    } catch (UnauthorizedException e) {
        return false;
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) 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