Search in sources :

Example 1 with Projects

use of com.walmartlabs.concord.server.jooq.tables.Projects in project concord by walmartlabs.

the class TriggerScheduleDao method findNext.

public TriggerSchedulerEntry findNext() {
    return txResult(tx -> {
        // TODO fetch everything in a single request?
        Map<String, Object> e = tx.select(TRIGGER_SCHEDULE.TRIGGER_ID, TRIGGER_SCHEDULE.FIRE_AT).from(TRIGGER_SCHEDULE).where(TRIGGER_SCHEDULE.FIRE_AT.le(currentOffsetDateTime())).limit(1).forUpdate().skipLocked().fetchOneMap();
        if (e == null) {
            return null;
        }
        UUID id = (UUID) e.get(TRIGGER_SCHEDULE.TRIGGER_ID.getName());
        OffsetDateTime fireAt = (OffsetDateTime) e.get(TRIGGER_SCHEDULE.FIRE_AT.getName());
        Triggers t = TRIGGERS.as("t");
        Projects p = PROJECTS.as("p");
        Repositories r = REPOSITORIES.as("r");
        Organizations o = ORGANIZATIONS.as("o");
        Field<UUID> orgIdField = select(p.ORG_ID).from(p).where(p.PROJECT_ID.eq(t.PROJECT_ID)).asField();
        Record13<UUID, UUID, String, UUID, String, UUID, String, String[], JSONB, JSONB, JSONB, OffsetDateTime, String> record = tx.select(t.TRIGGER_ID, orgIdField, o.ORG_NAME, t.PROJECT_ID, p.PROJECT_NAME, t.REPO_ID, r.REPO_NAME, t.ACTIVE_PROFILES, t.ARGUMENTS, t.TRIGGER_CFG, t.CONDITIONS, currentOffsetDateTime(), t.EVENT_SOURCE).from(t, p, r, o).where(t.TRIGGER_ID.eq(id).and(t.PROJECT_ID.eq(p.PROJECT_ID)).and(p.PROJECT_ID.eq(r.PROJECT_ID)).and(p.ORG_ID.eq(o.ORG_ID)).and(t.REPO_ID.eq(r.REPO_ID))).fetchOne();
        if (record == null) {
            return null;
        }
        UUID triggerId = record.value1();
        UUID orgId = record.value2();
        String organizationName = record.value3();
        UUID projectId = record.value4();
        String projectName = record.value5();
        UUID repoId = record.value6();
        String repositoryName = record.value7();
        List<String> activeProfiles = toList(record.value8());
        Map<String, Object> arguments = objectMapper.fromJSONB(record.value9());
        Map<String, Object> cfg = objectMapper.fromJSONB(record.value10());
        Map<String, Object> conditions = objectMapper.fromJSONB(record.value11());
        OffsetDateTime now = record.value12();
        String eventSource = record.value13();
        TriggerSchedulerEntry result = new TriggerSchedulerEntry(fireAt, triggerId, orgId, organizationName, projectId, projectName, repoId, repositoryName, conditions, cfg, activeProfiles, arguments, eventSource);
        ZoneId zoneId = null;
        if (conditions.get(Constants.Trigger.CRON_TIMEZONE) != null) {
            zoneId = TimeZone.getTimeZone((String) conditions.get(Constants.Trigger.CRON_TIMEZONE)).toZoneId();
        }
        updateFireAt(tx, id, CronUtils.nextExecution(now, (String) conditions.get(Constants.Trigger.CRON_SPEC), zoneId));
        return result;
    });
}
Also used : Repositories(com.walmartlabs.concord.server.jooq.tables.Repositories) ZoneId(java.time.ZoneId) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Triggers(com.walmartlabs.concord.server.jooq.tables.Triggers) OffsetDateTime(java.time.OffsetDateTime) Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations)

Example 2 with Projects

use of com.walmartlabs.concord.server.jooq.tables.Projects in project concord by walmartlabs.

the class ConcurrentProcessFilterDao method computeProcessesPerOrg.

private List<UUID> computeProcessesPerOrg(DSLContext tx, UUID orgId) {
    ProcessQueue q = ProcessQueue.PROCESS_QUEUE.as("q");
    Projects p = Projects.PROJECTS.as("p");
    return tx.select(q.INSTANCE_ID).from(q).innerJoin(p).on(q.PROJECT_ID.eq(p.PROJECT_ID)).where(p.ORG_ID.eq(orgId).and(q.CURRENT_STATUS.in(RUNNING_PROCESS_STATUSES))).fetch(Record1::value1);
}
Also used : ProcessQueue(com.walmartlabs.concord.server.jooq.tables.ProcessQueue) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Record1(org.jooq.Record1)

Example 3 with Projects

use of com.walmartlabs.concord.server.jooq.tables.Projects in project concord by walmartlabs.

the class TriggersDao method selectTriggers.

private SelectJoinStep<Record12<UUID, UUID, String, UUID, String, UUID, String, String, String[], JSONB, JSONB, JSONB>> selectTriggers(DSLContext tx) {
    Organizations o = ORGANIZATIONS.as("o");
    Projects p = PROJECTS.as("p");
    Repositories r = REPOSITORIES.as("r");
    return tx.select(TRIGGERS.TRIGGER_ID, o.ORG_ID, o.ORG_NAME, TRIGGERS.PROJECT_ID, p.PROJECT_NAME, TRIGGERS.REPO_ID, r.REPO_NAME, TRIGGERS.EVENT_SOURCE, TRIGGERS.ACTIVE_PROFILES, TRIGGERS.ARGUMENTS, TRIGGERS.CONDITIONS, TRIGGERS.TRIGGER_CFG).from(TRIGGERS).leftJoin(p).on(p.PROJECT_ID.eq(TRIGGERS.PROJECT_ID)).leftJoin(o).on(o.ORG_ID.eq(p.ORG_ID)).leftJoin(r).on(r.REPO_ID.eq(TRIGGERS.REPO_ID));
}
Also used : Repositories(com.walmartlabs.concord.server.jooq.tables.Repositories) Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Projects(com.walmartlabs.concord.server.jooq.tables.Projects)

Example 4 with Projects

use of com.walmartlabs.concord.server.jooq.tables.Projects in project concord by walmartlabs.

the class ProjectDao method get.

public ProjectEntry get(DSLContext tx, UUID projectId) {
    Projects p = PROJECTS.as("p");
    Users u = USERS.as("u");
    Field<String> orgNameField = select(ORGANIZATIONS.ORG_NAME).from(ORGANIZATIONS).where(ORGANIZATIONS.ORG_ID.eq(p.ORG_ID)).asField();
    Record15<UUID, String, String, UUID, String, JSONB, String, UUID, String, String, String, String, RawPayloadMode, JSONB, OutVariablesMode> r = tx.select(p.PROJECT_ID, p.PROJECT_NAME, p.DESCRIPTION, p.ORG_ID, orgNameField, p.PROJECT_CFG, p.VISIBILITY, p.OWNER_ID, u.USERNAME, u.DOMAIN, u.USER_TYPE, u.DISPLAY_NAME, p.RAW_PAYLOAD_MODE, p.META, p.OUT_VARIABLES_MODE).from(p).leftJoin(u).on(u.USER_ID.eq(p.OWNER_ID)).where(p.PROJECT_ID.eq(projectId)).fetchOne();
    if (r == null) {
        return null;
    }
    Result<Record13<UUID, UUID, String, String, String, String, String, Boolean, JSONB, UUID, String, String, Boolean>> repos = tx.select(REPOSITORIES.REPO_ID, REPOSITORIES.PROJECT_ID, REPOSITORIES.REPO_NAME, REPOSITORIES.REPO_URL, REPOSITORIES.REPO_BRANCH, REPOSITORIES.REPO_COMMIT_ID, REPOSITORIES.REPO_PATH, REPOSITORIES.IS_DISABLED, REPOSITORIES.META, SECRETS.SECRET_ID, SECRETS.SECRET_NAME, SECRETS.STORE_TYPE, REPOSITORIES.IS_TRIGGERS_DISABLED).from(REPOSITORIES).leftOuterJoin(SECRETS).on(SECRETS.SECRET_ID.eq(REPOSITORIES.SECRET_ID)).where(REPOSITORIES.PROJECT_ID.eq(projectId)).fetch();
    Map<String, RepositoryEntry> m = new HashMap<>();
    for (Record13<UUID, UUID, String, String, String, String, String, Boolean, JSONB, UUID, String, String, Boolean> repo : repos) {
        m.put(repo.get(REPOSITORIES.REPO_NAME), new RepositoryEntry(repo.get(REPOSITORIES.REPO_ID), repo.get(REPOSITORIES.PROJECT_ID), repo.get(REPOSITORIES.REPO_NAME), repo.get(REPOSITORIES.REPO_URL), repo.get(REPOSITORIES.REPO_BRANCH), repo.get(REPOSITORIES.REPO_COMMIT_ID), repo.get(REPOSITORIES.REPO_PATH), repo.get(REPOSITORIES.IS_DISABLED), repo.get(SECRETS.SECRET_ID), repo.get(SECRETS.SECRET_NAME), repo.get(SECRETS.STORE_TYPE), objectMapper.fromJSONB(repo.get(REPOSITORIES.META)), repo.get(REPOSITORIES.IS_TRIGGERS_DISABLED)));
    }
    Map<String, Object> cfg = objectMapper.fromJSONB(r.get(p.PROJECT_CFG));
    return new ProjectEntry(projectId, r.get(p.PROJECT_NAME), r.get(p.DESCRIPTION), r.get(p.ORG_ID), r.get(orgNameField), m, cfg, ProjectVisibility.valueOf(r.get(p.VISIBILITY)), toOwner(r.get(p.OWNER_ID), r.get(u.USERNAME), r.get(u.DOMAIN), r.get(u.DISPLAY_NAME), r.get(u.USER_TYPE)), r.get(p.RAW_PAYLOAD_MODE) != RawPayloadMode.DISABLED, r.get(p.RAW_PAYLOAD_MODE), objectMapper.fromJSONB(r.get(p.META)), r.get(p.OUT_VARIABLES_MODE));
}
Also used : OutVariablesMode(com.walmartlabs.concord.server.jooq.enums.OutVariablesMode) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Users(com.walmartlabs.concord.server.jooq.tables.Users) RawPayloadMode(com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)

Example 5 with Projects

use of com.walmartlabs.concord.server.jooq.tables.Projects in project concord by walmartlabs.

the class ProjectDao method list.

public List<ProjectEntry> list(UUID orgId, UUID currentUserId, Field<?> sortField, boolean asc, int offset, int limit, String filter) {
    Users u = USERS.as("u");
    Projects p = PROJECTS.as("p");
    Organizations o = ORGANIZATIONS.as("o");
    sortField = p.field(sortField);
    SelectOnConditionStep<Record13<UUID, String, String, UUID, String, String, UUID, String, String, String, String, RawPayloadMode, OutVariablesMode>> q = dsl().select(p.PROJECT_ID, p.PROJECT_NAME, p.DESCRIPTION, p.ORG_ID, o.ORG_NAME, p.VISIBILITY, p.OWNER_ID, u.USERNAME, u.DOMAIN, u.DISPLAY_NAME, u.USER_TYPE, p.RAW_PAYLOAD_MODE, p.OUT_VARIABLES_MODE).from(p).leftJoin(u).on(u.USER_ID.eq(p.OWNER_ID)).leftJoin(o).on(o.ORG_ID.eq(p.ORG_ID));
    if (currentUserId != null) {
        // public projects are visible for anyone
        Condition isPublic = p.VISIBILITY.eq(ProjectVisibility.PUBLIC.toString());
        // check if the user belongs to a team in the org
        SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId));
        Condition isInATeam = exists(selectOne().from(V_USER_TEAMS).where(V_USER_TEAMS.USER_ID.eq(currentUserId).and(V_USER_TEAMS.TEAM_ID.in(teamIds))));
        // check if the user owns projects in the org
        Condition ownsProjects = p.OWNER_ID.eq(currentUserId);
        // check if the user owns the org
        Condition ownsOrg = o.OWNER_ID.eq(currentUserId);
        // if any of those conditions true then the project must be visible
        q.where(or(isPublic, isInATeam, ownsProjects, ownsOrg));
    }
    if (orgId != null) {
        q.where(p.ORG_ID.eq(orgId));
    }
    if (sortField != null) {
        q.orderBy(asc ? sortField.asc() : sortField.desc());
    }
    if (filter != null) {
        q.where(p.PROJECT_NAME.containsIgnoreCase(filter));
    }
    if (offset > 0) {
        q.offset(offset);
    }
    if (limit > 0) {
        q.limit(limit);
    }
    return q.fetch(ProjectDao::toEntry);
}
Also used : Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Users(com.walmartlabs.concord.server.jooq.tables.Users)

Aggregations

Projects (com.walmartlabs.concord.server.jooq.tables.Projects)6 Organizations (com.walmartlabs.concord.server.jooq.tables.Organizations)4 Users (com.walmartlabs.concord.server.jooq.tables.Users)3 Repositories (com.walmartlabs.concord.server.jooq.tables.Repositories)2 OutVariablesMode (com.walmartlabs.concord.server.jooq.enums.OutVariablesMode)1 RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)1 ProcessQueue (com.walmartlabs.concord.server.jooq.tables.ProcessQueue)1 Secrets (com.walmartlabs.concord.server.jooq.tables.Secrets)1 Triggers (com.walmartlabs.concord.server.jooq.tables.Triggers)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneId (java.time.ZoneId)1 Record1 (org.jooq.Record1)1