Skip to content

Commit

Permalink
feat(clients/java): add resolve incident command
Browse files Browse the repository at this point in the history
  • Loading branch information
Zelldon committed Nov 26, 2018
1 parent e2eca8d commit 25c1df3
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 20 deletions.
Expand Up @@ -58,14 +58,10 @@ public interface JobClient {
* .send();
* </pre>
*
* The job is specified by the given event. The event must be the latest event of the job to
* ensure that the command is based on the latest state of the job. If it's not the latest one
* then the command is rejected.
*
* <p>If the job is linked to a workflow instance then this command will complete the related
* activity and continue the flow.
*
* @param event the latest job event
* @param jobKey the key which identifies the job
* @return a builder for the command
*/
CompleteJobCommandStep1 newCompleteCommand(long jobKey);
Expand All @@ -85,7 +81,7 @@ public interface JobClient {
* <p>If the given retries are greater than zero then this job will be picked up again by a job
* subscription. Otherwise, an incident is created for this job.
*
* @param jobKey the key of the job
* @param jobKey the key which identifies the job
* @return a builder for the command
*/
FailJobCommandStep1 newFailCommand(long jobKey);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import io.zeebe.client.api.commands.CreateWorkflowInstanceCommandStep1;
import io.zeebe.client.api.commands.DeployWorkflowCommandStep1;
import io.zeebe.client.api.commands.PublishMessageCommandStep1;
import io.zeebe.client.api.commands.ResolveIncidentCommandStep1;
import io.zeebe.client.api.commands.UpdatePayloadWorkflowInstanceCommandStep1;
import io.zeebe.client.api.commands.WorkflowRequestStep1;
import io.zeebe.client.api.commands.WorkflowResourceRequestStep1;
Expand Down Expand Up @@ -70,15 +71,11 @@ public interface WorkflowClient {
*
* <pre>
* workflowClient
* .newCancelInstanceCommand(workflowInstanceEvent)
* .newCancelInstanceCommand(workflowInstanceKey)
* .send();
* </pre>
*
* The workflow instance is specified by the given event. The event must be the latest event of
* the workflow instance to ensure that the command is based on the latest state of the workflow
* instance. If it's not the latest one then the command is rejected.
*
* @param event the latest workflow instance event
* @param workflowInstanceKey the key which identifies the corresponding workflow instance
* @return a builder for the command
*/
CancelWorkflowInstanceCommandStep1 newCancelInstanceCommand(long workflowInstanceKey);
Expand All @@ -88,18 +85,11 @@ public interface WorkflowClient {
*
* <pre>
* workflowClient
* .newUpdatePayloadCommand(workflowInstanceEvent)
* .newUpdatePayloadCommand(elementInstanceKey)
* .payload(json)
* .send();
* </pre>
*
* The workflow instance is specified by the given event. The event must be the latest event of
* the workflow instance to ensure that the command is based on the latest state of the workflow
* instance. If it's not the latest one then the command is rejected.
*
* <p>If the workflow instance failed because of a payload-related incident then it will try to
* resolve the incident with the given payload.
*
* @param elementInstanceKey the key of the element instance to update the payload for
* @return a builder for the command
*/
Expand Down Expand Up @@ -159,4 +149,18 @@ public interface WorkflowClient {
* @return a builder of the request
*/
WorkflowRequestStep1 newWorkflowRequest();

/**
* Command to resolve an existing incident.
*
* <pre>
* workflowClient
* .newResolveIncidentCommand(incidentKey)
* .send();
* </pre>
*
* @param incidentKey the key of the corresponding incident
* @return the builder for the command
*/
ResolveIncidentCommandStep1 newResolveIncidentCommand(long incidentKey);
}
@@ -0,0 +1,20 @@
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* 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.
*/
package io.zeebe.client.api.commands;

public interface ResolveIncidentCommandStep1 extends FinalCommandStep<Void> {
// the place for new optional parameters
}
Expand Up @@ -21,6 +21,7 @@
import io.zeebe.client.api.commands.CreateWorkflowInstanceCommandStep1;
import io.zeebe.client.api.commands.DeployWorkflowCommandStep1;
import io.zeebe.client.api.commands.PublishMessageCommandStep1;
import io.zeebe.client.api.commands.ResolveIncidentCommandStep1;
import io.zeebe.client.api.commands.UpdatePayloadWorkflowInstanceCommandStep1;
import io.zeebe.client.api.commands.WorkflowRequestStep1;
import io.zeebe.client.api.commands.WorkflowResourceRequestStep1;
Expand All @@ -30,6 +31,7 @@
import io.zeebe.client.impl.workflow.GetWorkflowCommandImpl;
import io.zeebe.client.impl.workflow.ListWorkflowsCommandImpl;
import io.zeebe.client.impl.workflow.PublishMessageCommandImpl;
import io.zeebe.client.impl.workflow.ResolveIncidentCommandImpl;
import io.zeebe.client.impl.workflow.UpdateWorkflowInstancePayloadCommandImpl;
import io.zeebe.gateway.protocol.GatewayGrpc.GatewayStub;

Expand Down Expand Up @@ -85,4 +87,9 @@ public WorkflowResourceRequestStep1 newResourceRequest() {
public WorkflowRequestStep1 newWorkflowRequest() {
return new ListWorkflowsCommandImpl(asyncStub);
}

@Override
public ResolveIncidentCommandStep1 newResolveIncidentCommand(long incidentKey) {
return new ResolveIncidentCommandImpl(asyncStub, incidentKey);
}
}
@@ -0,0 +1,46 @@
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* 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.
*/
package io.zeebe.client.impl.workflow;

import io.zeebe.client.api.ZeebeFuture;
import io.zeebe.client.api.commands.ResolveIncidentCommandStep1;
import io.zeebe.client.impl.ZeebeClientFutureImpl;
import io.zeebe.gateway.protocol.GatewayGrpc.GatewayStub;
import io.zeebe.gateway.protocol.GatewayOuterClass.ResolveIncidentRequest;
import io.zeebe.gateway.protocol.GatewayOuterClass.ResolveIncidentRequest.Builder;
import io.zeebe.gateway.protocol.GatewayOuterClass.ResolveIncidentResponse;

public class ResolveIncidentCommandImpl implements ResolveIncidentCommandStep1 {

private final GatewayStub asyncStub;
private final Builder builder;

public ResolveIncidentCommandImpl(GatewayStub asyncStub, long incidentKey) {
this.asyncStub = asyncStub;
this.builder = ResolveIncidentRequest.newBuilder().setIncidentKey(incidentKey);
}

@Override
public ZeebeFuture<Void> send() {
final ResolveIncidentRequest request = builder.build();

final ZeebeClientFutureImpl<Void, ResolveIncidentResponse> future =
new ZeebeClientFutureImpl<>();

asyncStub.resolveIncident(request, future);
return future;
}
}
Expand Up @@ -44,6 +44,8 @@
import io.zeebe.gateway.protocol.GatewayOuterClass.Partition.PartitionBrokerRole;
import io.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest;
import io.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageResponse;
import io.zeebe.gateway.protocol.GatewayOuterClass.ResolveIncidentRequest;
import io.zeebe.gateway.protocol.GatewayOuterClass.ResolveIncidentResponse;
import io.zeebe.gateway.protocol.GatewayOuterClass.TopologyRequest;
import io.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse;
import io.zeebe.gateway.protocol.GatewayOuterClass.UpdateJobRetriesRequest;
Expand Down Expand Up @@ -89,6 +91,8 @@ public RecordingGatewayService() {
addRequestHandler(ListWorkflowsRequest.class, r -> ListWorkflowsResponse.getDefaultInstance());
addRequestHandler(GetWorkflowRequest.class, r -> GetWorkflowResponse.getDefaultInstance());
addRequestHandler(ActivateJobsRequest.class, r -> ActivateJobsResponse.getDefaultInstance());
addRequestHandler(
ResolveIncidentRequest.class, r -> ResolveIncidentResponse.getDefaultInstance());
}

@Override
Expand Down Expand Up @@ -170,6 +174,12 @@ public void activateJobs(
handle(request, responseObserver);
}

@Override
public void resolveIncident(
ResolveIncidentRequest request, StreamObserver<ResolveIncidentResponse> responseObserver) {
handle(request, responseObserver);
}

public static Partition partition(int partitionId, PartitionBrokerRole role) {
return Partition.newBuilder().setPartitionId(partitionId).setRole(role).build();
}
Expand Down
@@ -0,0 +1,35 @@
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* 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.
*/
package io.zeebe.client.workflow;

import static org.assertj.core.api.Assertions.assertThat;

import io.zeebe.client.util.ClientTest;
import io.zeebe.gateway.protocol.GatewayOuterClass.ResolveIncidentRequest;
import org.junit.Test;

public class ResolveIncidentTest extends ClientTest {

@Test
public void shouldSendCommand() {
// when
client.workflowClient().newResolveIncidentCommand(123).send().join();

// then
final ResolveIncidentRequest request = gatewayService.getLastRequest();
assertThat(request.getIncidentKey()).isEqualTo(123);
}
}

0 comments on commit 25c1df3

Please sign in to comment.