-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KOGITO-6785] Serverless Workflow Correlation (#2160)
* Inserting serverless workflow correlation
- Loading branch information
1 parent
183cd82
commit a939408
Showing
46 changed files
with
1,102 additions
and
112 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
api/kogito-api/src/main/java/org/kie/kogito/correlation/CompositeCorrelation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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 org.kie.kogito.correlation; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.StringJoiner; | ||
import java.util.stream.Collectors; | ||
|
||
public class CompositeCorrelation implements Correlation<Set<? extends Correlation<?>>> { | ||
|
||
private String key; | ||
private Set<? extends Correlation<?>> correlations; | ||
|
||
public CompositeCorrelation(Set<? extends Correlation<?>> correlations) { | ||
this.key = buildKey(correlations); | ||
this.correlations = Collections.unmodifiableSet(correlations); | ||
} | ||
|
||
private static String buildKey(Set<? extends Correlation<?>> correlations) { | ||
return correlations.stream().map(Correlation::getKey).collect(Collectors.joining("|")); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public Set<? extends Correlation<?>> getValue() { | ||
return correlations; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof CompositeCorrelation)) { | ||
return false; | ||
} | ||
CompositeCorrelation that = (CompositeCorrelation) o; | ||
return Objects.equals(getValue(), that.getValue()) && Objects.equals(getKey(), that.getKey()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getValue(), getKey()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", CompositeCorrelation.class.getSimpleName() + "[", "]") | ||
.add("correlations=" + correlations) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
api/kogito-api/src/main/java/org/kie/kogito/correlation/CorrelationEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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 org.kie.kogito.correlation; | ||
|
||
public interface CorrelationEncoder { | ||
|
||
String encode(Correlation correlation); | ||
} |
41 changes: 41 additions & 0 deletions
41
api/kogito-api/src/main/java/org/kie/kogito/correlation/CorrelationInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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 org.kie.kogito.correlation; | ||
|
||
public class CorrelationInstance { | ||
|
||
private String correlationId;// encoded based on correlations | ||
private String correlatedId;// == processInstanceId | ||
private Correlation<?> correlation; | ||
|
||
public CorrelationInstance(String correlationId, String correlatedId, Correlation<?> correlation) { | ||
this.correlationId = correlationId; | ||
this.correlatedId = correlatedId; | ||
this.correlation = correlation; | ||
} | ||
|
||
public String getCorrelationId() { | ||
return correlationId; | ||
} | ||
|
||
public String getCorrelatedId() { | ||
return correlatedId; | ||
} | ||
|
||
public Correlation<?> getCorrelation() { | ||
return correlation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
api/kogito-api/src/main/java/org/kie/kogito/correlation/CorrelationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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 org.kie.kogito.correlation; | ||
|
||
import java.util.Optional; | ||
|
||
public interface CorrelationService { | ||
|
||
CorrelationInstance create(Correlation correlation, String correlatedId); | ||
|
||
Optional<CorrelationInstance> find(Correlation correlation); | ||
|
||
Optional<CorrelationInstance> findByCorrelatedId(String correlatedId); | ||
|
||
void delete(Correlation correlation); | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
api/kogito-api/src/main/java/org/kie/kogito/correlation/SimpleCorrelation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* 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 org.kie.kogito.correlation; | ||
|
||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
|
||
public class SimpleCorrelation<T> implements Correlation<T> { | ||
|
||
private String key; | ||
private T value; | ||
|
||
public SimpleCorrelation(String key) { | ||
this(key, null); | ||
} | ||
|
||
public SimpleCorrelation(String key, T value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public T getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof SimpleCorrelation)) { | ||
return false; | ||
} | ||
SimpleCorrelation that = (SimpleCorrelation) o; | ||
return Objects.equals(getKey(), that.getKey()) && Objects.equals(getValue(), that.getValue()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getKey(), getValue()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", SimpleCorrelation.class.getSimpleName() + "[", "]") | ||
.add("key='" + key + "'") | ||
.add("value=" + value) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.