-
Notifications
You must be signed in to change notification settings - Fork 56
Adding an ability to use a default implementation for sending history. #5347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* Copyright 2023 Telstra Open Source | ||
| * | ||
| * 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.openkilda.wfm; | ||
|
|
||
| import org.apache.storm.tuple.Tuple; | ||
| import org.apache.storm.tuple.Values; | ||
|
|
||
| /** | ||
| * This interface represents something that has CommandContext and | ||
| * knows how to emit the payload via the given Storm stream. | ||
| */ | ||
| public interface ContextEmittable { | ||
| CommandContext getCommandContext(); | ||
|
|
||
| void emitWithContext(String stream, Tuple input, Values payload); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* Copyright 2023 Telstra Open Source | ||
| * | ||
| * 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.openkilda.wfm; | ||
|
|
||
| import org.openkilda.messaging.info.InfoMessage; | ||
| import org.openkilda.wfm.share.history.model.FlowHistoryHolder; | ||
|
|
||
| import lombok.NonNull; | ||
| import org.apache.storm.tuple.Values; | ||
|
|
||
| /** | ||
| * This is a default implementation for sending history updates that are accessible later via HistoryService. | ||
| * A topology that uses the bolt implementing this interface must register a path to history bolt. | ||
| * That is, in a topology that extends AbstractTopology, declare a Kafka bolt and specify a component ID | ||
| * that is a source of history updates in the fields grouping and declare a stream. | ||
| * TODO add a readme.md with the details and example. | ||
| */ | ||
| public interface DefaultHistoryUpdateCarrier extends HistoryUpdateCarrier, TupleIdentifiable, ContextEmittable { | ||
|
|
||
| @Override | ||
| default void sendHistoryUpdate(@NonNull FlowHistoryHolder historyHolder) { | ||
| InfoMessage message = new InfoMessage(historyHolder, getCommandContext().getCreateTime(), | ||
| getCommandContext().getCorrelationId()); | ||
| emitWithContext(getHistoryStreamName(), getCurrentTuple(), | ||
| new Values(historyHolder.getTaskId(), message)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.openkilda.wfm.topology.flowhs.service.common; | ||
| package org.openkilda.wfm; | ||
|
|
||
| import org.openkilda.wfm.share.history.model.FlowHistoryHolder; | ||
|
|
||
|
|
@@ -25,4 +25,8 @@ public interface HistoryUpdateCarrier { | |
| * Sends main events to history bolt. | ||
| */ | ||
| void sendHistoryUpdate(FlowHistoryHolder historyHolder); | ||
|
|
||
| default String getHistoryStreamName() { | ||
| return "HUB_TO_HISTORY_TOPOLOGY_SENDER"; | ||
| } | ||
|
Comment on lines
+29
to
+31
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be more convenient to keep HUB_TO_HISTORY_TOPOLOGY_SENDER constant in the Stream enum?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I have a thought that it needs to be in some place that is accessible in the bolts and the service at the same time. We need this constant when configuring topologies, so it would be convenient to have some unified approach of adding. If it is a helper method then it can't be enum that we have in the topology package.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* Copyright 2023 Telstra Open Source | ||
| * | ||
| * 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.openkilda.wfm; | ||
|
|
||
| import org.apache.storm.tuple.Tuple; | ||
|
|
||
| /** | ||
| * This interface represents something that has a distinct tuple that can be used as an anchor in Storm. | ||
| */ | ||
| public interface TupleIdentifiable { | ||
| Tuple getCurrentTuple(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, you decided to point out explicitly AccessLevel.PUBLIC only to keep the common behaviour here, like as it is in the cases for AccessLevel.PROTECTED?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a part of an interface now, so it has to be public