-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-14230 Implement start/stop flow C2 operations in MiNiFi
- Loading branch information
Showing
16 changed files
with
704 additions
and
25 deletions.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
...-service/src/main/java/org/apache/nifi/c2/client/service/operation/FlowStateStrategy.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,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.nifi.c2.client.service.operation; | ||
|
||
import org.apache.nifi.c2.protocol.api.C2OperationState.OperationState; | ||
|
||
public interface FlowStateStrategy { | ||
|
||
OperationState start(); | ||
|
||
OperationState stop(); | ||
} |
77 changes: 77 additions & 0 deletions
77
.../src/main/java/org/apache/nifi/c2/client/service/operation/StartFlowOperationHandler.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,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.nifi.c2.client.service.operation; | ||
|
||
import org.apache.nifi.c2.protocol.api.C2Operation; | ||
import org.apache.nifi.c2.protocol.api.C2OperationAck; | ||
import org.apache.nifi.c2.protocol.api.C2OperationState; | ||
import org.apache.nifi.c2.protocol.api.OperandType; | ||
import org.apache.nifi.c2.protocol.api.OperationType; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import static java.util.Optional.ofNullable; | ||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
|
||
public class StartFlowOperationHandler implements C2OperationHandler { | ||
|
||
public static final String NOT_APPLIED_DETAILS = "Failed to start flow, please check the log for errors"; | ||
public static final String PARTIALLY_APPLIED_DETAILS = "Some components failed to start, please check the log for errors"; | ||
public static final String FULLY_APPLIED_DETAILS = "Flow started"; | ||
public static final String UNEXPECTED_DETAILS = "Unexpected status, please check the log for errors"; | ||
|
||
private final FlowStateStrategy flowStateStrategy; | ||
|
||
public StartFlowOperationHandler(FlowStateStrategy flowStateStrategy) { | ||
this.flowStateStrategy = flowStateStrategy; | ||
} | ||
|
||
@Override | ||
public OperationType getOperationType() { | ||
return OperationType.START; | ||
} | ||
|
||
@Override | ||
public OperandType getOperandType() { | ||
return OperandType.FLOW; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getProperties() { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
@Override | ||
public C2OperationAck handle(C2Operation operation) { | ||
String operationId = ofNullable(operation.getIdentifier()).orElse(EMPTY); | ||
C2OperationState.OperationState operationState = flowStateStrategy.start(); | ||
|
||
C2OperationState resultState = operationState( | ||
operationState, | ||
switch (operationState) { | ||
case NOT_APPLIED -> NOT_APPLIED_DETAILS; | ||
case FULLY_APPLIED -> FULLY_APPLIED_DETAILS; | ||
case PARTIALLY_APPLIED -> PARTIALLY_APPLIED_DETAILS; | ||
default -> UNEXPECTED_DETAILS; | ||
} | ||
); | ||
|
||
return operationAck(operationId, resultState); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...e/src/main/java/org/apache/nifi/c2/client/service/operation/StopFlowOperationHandler.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,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.nifi.c2.client.service.operation; | ||
|
||
import org.apache.nifi.c2.protocol.api.C2Operation; | ||
import org.apache.nifi.c2.protocol.api.C2OperationAck; | ||
import org.apache.nifi.c2.protocol.api.C2OperationState; | ||
import org.apache.nifi.c2.protocol.api.OperandType; | ||
import org.apache.nifi.c2.protocol.api.OperationType; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import static java.util.Optional.ofNullable; | ||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
|
||
public class StopFlowOperationHandler implements C2OperationHandler { | ||
|
||
public static final String NOT_APPLIED_DETAILS = "Failed to stop flow, please check the log for errors"; | ||
public static final String FULLY_APPLIED_DETAILS = "Flow stopped"; | ||
public static final String PARTIALLY_APPLIED_DETAILS = "Some components failed to stop, please check the log for errors"; | ||
public static final String UNEXPECTED_DETAILS = "Unexpected status, please check the log for errors"; | ||
|
||
|
||
private final FlowStateStrategy flowStateStrategy; | ||
|
||
public StopFlowOperationHandler(FlowStateStrategy flowStateStrategy) { | ||
this.flowStateStrategy = flowStateStrategy; | ||
} | ||
|
||
@Override | ||
public OperationType getOperationType() { | ||
return OperationType.STOP; | ||
} | ||
|
||
@Override | ||
public OperandType getOperandType() { | ||
return OperandType.FLOW; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getProperties() { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
@Override | ||
public C2OperationAck handle(C2Operation operation) { | ||
String operationId = ofNullable(operation.getIdentifier()).orElse(EMPTY); | ||
C2OperationState.OperationState operationState = flowStateStrategy.stop(); | ||
|
||
C2OperationState resultState = operationState( | ||
operationState, | ||
switch (operationState) { | ||
case NOT_APPLIED -> NOT_APPLIED_DETAILS; | ||
case FULLY_APPLIED -> FULLY_APPLIED_DETAILS; | ||
case PARTIALLY_APPLIED -> PARTIALLY_APPLIED_DETAILS; | ||
default -> UNEXPECTED_DETAILS; | ||
} | ||
); | ||
|
||
return operationAck(operationId, resultState); | ||
} | ||
} |
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.