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));
}
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);
}
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";
}
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);
}
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;
}
}
Aggregations