Skip to content

Commit

Permalink
Merge branch 'master' into brig/v2-parallel-exception-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
brig authored Feb 13, 2025
2 parents 92882c1 + 08d9092 commit ed0e4c6
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.inject.Inject;
import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;

@Named("http")
@DryRunReady
Expand All @@ -40,9 +39,12 @@ public HttpTaskV2(Context context) {

@Override
public TaskResult execute(Variables input) throws Exception {
Configuration config = Configuration.custom().build(context.workingDirectory().toString(), input.toMap(), context.processConfiguration().debug());
var inputMap = new HashMap<>(context.defaultVariables().toMap());
inputMap.putAll(input.toMap());

Map<String, Object> response = new HashMap<>(SimpleHttpClient.create(config, context.processConfiguration().dryRun()).execute().getResponse());
var config = Configuration.custom().build(context.workingDirectory().toString(), inputMap, context.processConfiguration().debug());

var response = new HashMap<>(SimpleHttpClient.create(config, context.processConfiguration().dryRun()).execute().getResponse());
return TaskResult.of((boolean)response.remove("success"), (String)response.remove("errorString"), response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.walmartlabs.concord.plugins.misc;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2025 Walmart Inc.
* -----
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =====
*/

import com.walmartlabs.concord.runtime.v2.sdk.Task;

import javax.inject.Named;
import java.util.Base64;

import static java.nio.charset.StandardCharsets.UTF_8;

@Named("base64")
public class Base64TaskV2 implements Task {

/**
* Encodes bytes of a UTF-8 string as a base64 string.
*/
public String encode(String raw) {
return Base64.getEncoder().encodeToString(raw.getBytes(UTF_8));
}

/**
* Decodes a base64-encoded string.
*/
public String decode(String base64) {
return new String(Base64.getDecoder().decode(base64), UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public String current(String pattern) {
return DateTimeFormatter.ofPattern(pattern).format(ZonedDateTime.now());
}

public String currentISO() {
return current("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
}

public String currentWithZone(String zone, String pattern) {
return DateTimeFormatter.ofPattern(pattern).format(ZonedDateTime.now(ZoneId.of(zone)));
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/java/com/walmartlabs/concord/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ public static class Multipart {
public static final String SYNC = "sync";

public static final String META = "meta";

public static final String ORDER_ID = "orderId";
}

public static class Headers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@
<include file="v2.12.0.xml" relativeToChangelogFile="true"/>
<include file="v2.14.0.xml" relativeToChangelogFile="true"/>
<include file="v2.21.0.xml" relativeToChangelogFile="true"/>
<include file="v2.22.0.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">

<changeSet id="2220000" author="[email protected]">
<addColumn tableName="UI_PROCESS_CARDS">
<column name="ORDER_ID" type="int">
<constraints nullable="true"/>
</column>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public static UUID assertUuid(MultipartInput input, String key) {
throw new ConcordApplicationException(key + " not specified", Response.Status.BAD_REQUEST);
}

public static Integer getInt(MultipartInput input, String key) {
String s = getString(input, key);
if (s == null) {
return null;
}
return Integer.parseInt(s);
}

public static InputStream getStream(MultipartInput input, String key) {
try {
for (InputPart p : input.getParts()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public interface ProcessCardEntry extends Serializable {

boolean isCustomForm();

@Nullable
Integer orderId();

static ImmutableProcessCardEntry.Builder builder() {
return ImmutableProcessCardEntry.builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public List<ProcessCardEntry> listUserCards(UUID userId) {
return dao.listCards(userId);
}

public ProcessCardOperationResponse createOrUpdate(UUID id, UUID projectId, UUID repoId, String name, Optional<String> entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data) {
public ProcessCardOperationResponse createOrUpdate(UUID id, UUID projectId, UUID repoId, String name, Optional<String> entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data, Integer orderId) {
boolean exists;
if (id == null) {
if (projectId == null) {
Expand All @@ -110,12 +110,12 @@ public ProcessCardOperationResponse createOrUpdate(UUID id, UUID projectId, UUID
}

if (!exists) {
UUID resultId = dao.insert(id, projectId, repoId, name, entryPoint.orElse(Constants.Request.DEFAULT_ENTRY_POINT_NAME), description, icon, form, data);
UUID resultId = dao.insert(id, projectId, repoId, name, entryPoint.orElse(Constants.Request.DEFAULT_ENTRY_POINT_NAME), description, icon, form, data, orderId);
return new ProcessCardOperationResponse(resultId, OperationResult.CREATED);
} else {
assertAccess(id);

dao.update(id, projectId, repoId, name, entryPoint.orElse(null), description, icon, form, data);
dao.update(id, projectId, repoId, name, entryPoint.orElse(null), description, icon, form, data, orderId);
return new ProcessCardOperationResponse(id, OperationResult.UPDATED);
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public Optional<UUID> getIdByName(UUID projectId, String name) {
.fetchOptional(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID);
}

public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data) {
public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data, Integer orderId) {
return txResult(tx -> {
String sql = tx.insertInto(UI_PROCESS_CARDS)
.columns(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID,
Expand All @@ -173,8 +173,9 @@ public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String
UI_PROCESS_CARDS.ICON,
UI_PROCESS_CARDS.FORM,
UI_PROCESS_CARDS.DATA,
UI_PROCESS_CARDS.OWNER_ID)
.values((UUID) null, null, null, null, null, null, null, null, null, null)
UI_PROCESS_CARDS.OWNER_ID,
UI_PROCESS_CARDS.ORDER_ID)
.values((UUID) null, null, null, null, null, null, null, null, null, null, null)
.returning(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.getSQL();

Expand All @@ -190,6 +191,7 @@ public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String
ps.setBinaryStream(8, form);
ps.setObject(9, data != null ? objectMapper.toJSONB(data).data() : null);
ps.setObject(10, UserPrincipal.assertCurrent().getId());
ps.setObject(11, orderId);

try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
Expand All @@ -205,7 +207,7 @@ public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String

public void update(UUID cardId, UUID projectId, UUID repoId, String name,
String entryPoint, String description, InputStream icon, InputStream form,
Map<String, Object> data) {
Map<String, Object> data, Integer orderId) {
tx(tx -> {
List<Object> params = new ArrayList<>();
UpdateSetStep<UiProcessCardsRecord> q = tx.update(UI_PROCESS_CARDS);
Expand Down Expand Up @@ -254,6 +256,11 @@ public void update(UUID cardId, UUID projectId, UUID repoId, String name,
return;
}

if (orderId != null) {
q.set(UI_PROCESS_CARDS.ORDER_ID, (Integer) null);
params.add(orderId);
}

String sql = q.set(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID, cardId)
.where(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID.eq(cardId))
.getSQL();
Expand Down Expand Up @@ -358,7 +365,7 @@ private List<ProcessCardEntry> listCards(DSLContext tx, UUID userId) {
.where(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID.in(userCardsFilter));

return query
.orderBy(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.orderBy(UI_PROCESS_CARDS.ORDER_ID, UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.fetch(this::toEntry);
}

Expand Down Expand Up @@ -404,7 +411,7 @@ private static <T> Optional<T> getInputStream(DSLContext tx, String sql, UUID ca
});
}

private static SelectOnConditionStep<Record12<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean>> buildSelect(DSLContext tx) {
private static SelectOnConditionStep<Record13<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean, Integer>> buildSelect(DSLContext tx) {
Field<Boolean> isCustomForm = when(field(UI_PROCESS_CARDS.FORM).isNotNull(), true).otherwise(false);

return tx.select(
Expand All @@ -419,14 +426,15 @@ private static SelectOnConditionStep<Record12<UUID, UUID, String, UUID, String,
UI_PROCESS_CARDS.ENTRY_POINT,
UI_PROCESS_CARDS.DESCRIPTION,
UI_PROCESS_CARDS.ICON,
isCustomForm.as("isCustomForm"))
isCustomForm.as("isCustomForm"),
UI_PROCESS_CARDS.ORDER_ID)
.from(UI_PROCESS_CARDS)
.leftJoin(REPOSITORIES).on(REPOSITORIES.REPO_ID.eq(UI_PROCESS_CARDS.REPO_ID))
.leftJoin(PROJECTS).on(PROJECTS.PROJECT_ID.eq(UI_PROCESS_CARDS.PROJECT_ID))
.leftJoin(ORGANIZATIONS).on(ORGANIZATIONS.ORG_ID.eq(PROJECTS.ORG_ID));
}

private ProcessCardEntry toEntry(Record12<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean> r) {
private ProcessCardEntry toEntry(Record13<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean, Integer> r) {
return ProcessCardEntry.builder()
.id(r.get(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID))
.orgName(r.get(ORGANIZATIONS.ORG_NAME))
Expand All @@ -437,6 +445,7 @@ private ProcessCardEntry toEntry(Record12<UUID, UUID, String, UUID, String, UUID
.description(r.get(UI_PROCESS_CARDS.DESCRIPTION))
.icon(encodeBase64(r.get(UI_PROCESS_CARDS.ICON)))
.isCustomForm(r.get("isCustomForm", Boolean.class))
.orderId(r.get(UI_PROCESS_CARDS.ORDER_ID))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public String getEntryPoint() {
return MultipartUtils.getString(input, Constants.Multipart.ENTRY_POINT);
}

@Schema(name = Constants.Multipart.ORDER_ID)
public Integer getOrderId() {
return MultipartUtils.getInt(input, Constants.Multipart.ORDER_ID);
}

@Schema(name = "name")
public String getName() {
return MultipartUtils.getString(input, "name");
Expand Down Expand Up @@ -105,4 +110,5 @@ public InputStream getIcon() {
public InputStream getForm() {
return MultipartUtils.getStream(input, "form");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ public ProcessCardOperationResponse createOrUpdate(
String description = r.getDescription();
Map<String, Object> data = r.getData();
UUID id = r.getId();
Integer orderId = r.getOrderId();

try (InputStream icon = r.getIcon();
InputStream form = r.getForm()) {
return processCardManager.createOrUpdate(id, projectId, repoId, name, entryPoint, description, icon, form, data);
return processCardManager.createOrUpdate(id, projectId, repoId, name, entryPoint, description, icon, form, data, orderId);
}
}

Expand Down

0 comments on commit ed0e4c6

Please sign in to comment.