Skip to content

Commit

Permalink
[SELC-5642] feat: added new workflow executor for GPU
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpaolodidato89 authored Nov 28, 2024
1 parent 9f28bec commit 17ad2d2
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public void onboardingsOrchestrator(
workflowExecutor = new WorkflowExecutorForApprove(objectMapper, optionsRetry);
case FOR_APPROVE_PT ->
workflowExecutor = new WorkflowExecutorForApprovePt(objectMapper, optionsRetry);
case FOR_APPROVE_GPU ->
workflowExecutor = new WorkflowExecutorForApproveGpu(objectMapper, optionsRetry);
case CONFIRMATION ->
workflowExecutor = new WorkflowExecutorConfirmation(objectMapper, optionsRetry);
case CONFIRMATION_AGGREGATE ->
Expand Down Expand Up @@ -254,7 +256,7 @@ public void buildContract(
}

/** This HTTP-triggered function invokes an orchestration to build attachments and save tokens */
@FunctionName("BuildAttachmentsAndSaveTokens")
@FunctionName("TriggerBuildAttachmentsAndSaveTokens")
public HttpResponseMessage buildAttachmentsAndSaveTokens(
@HttpTrigger(
name = "req",
Expand Down Expand Up @@ -293,7 +295,7 @@ public HttpResponseMessage buildAttachmentsAndSaveTokens(
* for invoking the activity function "BuildAttachment" and "saveTokenAttachment" until there are
* no more attachment to process.
*/
@FunctionName("BuildAttachmentAndSaveToken")
@FunctionName(BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY)
public void buildAttachmentAndSaveToken(
@DurableOrchestrationTrigger(name = "taskOrchestrationContext") TaskOrchestrationContext ctx,
ExecutionContext functionContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ActivityName {
public static final String EXISTS_DELEGATION_ACTIVITY = "ExistsDelegationActivity";
public static final String DELETE_MANAGERS_BY_IC_AND_ADE = "DeleteManagersByIcAndAde";
public static final String RETRIEVE_AGGREGATES_ACTIVITY = "RetrieveAggregates";
public static final String BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY = "BuildAttachmentAndSaveTokens";

private ActivityName() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingString;
import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingWorkflowString;

public record WorkflowExecutorForApprove(ObjectMapper objectMapper, TaskOptions optionsRetry) implements WorkflowExecutor {
public class WorkflowExecutorForApprove implements WorkflowExecutor {

private final ObjectMapper objectMapper;
private final TaskOptions optionsRetry;

public WorkflowExecutorForApprove(ObjectMapper objectMapper, TaskOptions optionsRetry) {
this.objectMapper = objectMapper;
this.optionsRetry = optionsRetry;
}

@Override
public Optional<OnboardingStatus> executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) {
Expand All @@ -42,4 +50,14 @@ public Optional<OnboardingStatus> executePendingState(TaskOrchestrationContext c
public OnboardingWorkflow createOnboardingWorkflow(Onboarding onboarding) {
return new OnboardingWorkflowInstitution(onboarding, INSTITUTION.name());
}

@Override
public ObjectMapper objectMapper() {
return objectMapper;
}

@Override
public TaskOptions optionsRetry() {
return optionsRetry;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.pagopa.selfcare.onboarding.workflow;

import static it.pagopa.selfcare.onboarding.functions.utils.ActivityName.*;
import static it.pagopa.selfcare.onboarding.utils.Utils.getOnboardingString;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.durabletask.TaskOptions;
import com.microsoft.durabletask.TaskOrchestrationContext;
import it.pagopa.selfcare.onboarding.common.OnboardingStatus;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow;
import java.util.Optional;

public class WorkflowExecutorForApproveGpu extends WorkflowExecutorForApprove {

public WorkflowExecutorForApproveGpu(ObjectMapper objectMapper, TaskOptions optionsRetry) {
super(objectMapper, optionsRetry);
}

@Override
public Optional<OnboardingStatus> executeRequestState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) {
String onboardingString = getOnboardingString(super.objectMapper(), onboardingWorkflow.getOnboarding());
ctx.callSubOrchestrator(BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY, onboardingString, String.class);
ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, super.optionsRetry(), String.class).await();
return Optional.of(OnboardingStatus.TOBEVALIDATED);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,77 @@ void onboardingOrchestratorUsersEaPending() {
function.onboardingsOrchestrator(orchestrationContext, executionContext);
}

@Test
void onboardingsOrchestratorForApproveGpu() {
Onboarding onboarding = new Onboarding();
onboarding.setId("onboardingId");
onboarding.setStatus(OnboardingStatus.REQUEST);
onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU);

TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding);

function.onboardingsOrchestrator(orchestrationContext, executionContext);

ArgumentCaptor<String> captorActivity = ArgumentCaptor.forClass(String.class);
verify(orchestrationContext, times(1))
.callActivity(captorActivity.capture(), any(), any(), any());

assertEquals(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, captorActivity.getAllValues().get(0));

Mockito.verify(orchestrationContext, times(1))
.callSubOrchestrator(eq(BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY), any(), any());

verify(service, times(1))
.updateOnboardingStatus(onboarding.getId(), OnboardingStatus.TOBEVALIDATED);
}

@Test
void onboardingsOrchestratorForApproveGpuWhenIsPending() {
Onboarding onboarding = new Onboarding();
onboarding.setId("onboardingId");
onboarding.setStatus(OnboardingStatus.PENDING);
onboarding.setInstitution(new Institution());
onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU);

TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding);

function.onboardingsOrchestrator(orchestrationContext, executionContext);

ArgumentCaptor<String> captorActivity = ArgumentCaptor.forClass(String.class);
verify(orchestrationContext, times(5))
.callActivity(captorActivity.capture(), any(), any(), any());
assertEquals(CREATE_INSTITUTION_ACTIVITY, captorActivity.getAllValues().get(0));
assertEquals(CREATE_ONBOARDING_ACTIVITY, captorActivity.getAllValues().get(1));
assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(2));
assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(3));
assertEquals(SEND_MAIL_COMPLETION_ACTIVITY, captorActivity.getAllValues().get(4));

verify(service, times(1))
.updateOnboardingStatus(onboarding.getId(), OnboardingStatus.COMPLETED);
}

@Test
void onboardingsOrchestratorForApproveGpuWhenToBeValidated() {
Onboarding onboarding = new Onboarding();
onboarding.setId("onboardingId");
onboarding.setStatus(OnboardingStatus.TOBEVALIDATED);
onboarding.setWorkflowType(WorkflowType.FOR_APPROVE_GPU);

TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding);

function.onboardingsOrchestrator(orchestrationContext, executionContext);

ArgumentCaptor<String> captorActivity = ArgumentCaptor.forClass(String.class);
verify(orchestrationContext, times(3))
.callActivity(captorActivity.capture(), any(), any(), any());
assertEquals(BUILD_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(0));
assertEquals(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(1));
assertEquals(SEND_MAIL_REGISTRATION_FOR_CONTRACT_WHEN_APPROVE_ACTIVITY, captorActivity.getAllValues().get(2));

verify(service, times(1))
.updateOnboardingStatus(onboarding.getId(), OnboardingStatus.PENDING);
}

private Product createDummyProduct() {
Product product = new Product();
product.setTitle("Title");
Expand Down Expand Up @@ -1173,12 +1244,4 @@ private static Map<String, ContractTemplate> createDummyContractTemplateInstitut
return institutionTemplate;
}

private static Map<String, ContractTemplate> createDummyContractTemplateUser() {
Map<String, ContractTemplate> institutionTemplate = new HashMap<>();
ContractTemplate conctractTemplate = new ContractTemplate();
conctractTemplate.setContractTemplatePath("example");
conctractTemplate.setContractTemplateVersion("version");
institutionTemplate.put("default", conctractTemplate);
return institutionTemplate;
}
}

0 comments on commit 17ad2d2

Please sign in to comment.