-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kafka_isssues447): add command util and update version to 0.5.2 (#…
…709) Signed-off-by: Robin Han <[email protected]>
- Loading branch information
Showing
7 changed files
with
185 additions
and
20 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
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
80 changes: 80 additions & 0 deletions
80
s3stream/src/main/java/com/automq/stream/s3/failover/Serverless.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,80 @@ | ||
/* | ||
* 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 com.automq.stream.s3.failover; | ||
|
||
import java.util.List; | ||
|
||
public interface Serverless { | ||
|
||
/** | ||
* Attach volume to the target node. | ||
* @param volumeId volume id | ||
* @param nodeId target node id | ||
* @return attached device name | ||
*/ | ||
String attach(String volumeId, String nodeId); | ||
|
||
/** | ||
* Delete the volume | ||
* @param volumeId volume id | ||
*/ | ||
void delete(String volumeId); | ||
|
||
/** | ||
* Fence the first attached node access to the volume | ||
* @param volumeId volume id | ||
*/ | ||
void fence(String volumeId); | ||
|
||
/** | ||
* Scan failed node | ||
* @return {@link FailedNode} list | ||
*/ | ||
List<FailedNode> scan(); | ||
|
||
class FailedNode { | ||
private int nodeId; | ||
private String volumeId; | ||
|
||
public int getNodeId() { | ||
return nodeId; | ||
} | ||
|
||
public void setNodeId(int nodeId) { | ||
this.nodeId = nodeId; | ||
} | ||
|
||
public String getVolumeId() { | ||
return volumeId; | ||
} | ||
|
||
public void setVolumeId(String volumeId) { | ||
this.volumeId = volumeId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FailedNode{" + | ||
"nodeId=" + nodeId + | ||
", volumeId='" + volumeId + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
s3stream/src/main/java/com/automq/stream/utils/CommandResult.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,51 @@ | ||
/* | ||
* 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 com.automq.stream.utils; | ||
|
||
public class CommandResult { | ||
private final int code; | ||
private final String stdout; | ||
private final String stderr; | ||
|
||
public CommandResult(int code, String stdout, String stderr) { | ||
this.code = code; | ||
this.stdout = stdout; | ||
this.stderr = stderr; | ||
} | ||
|
||
public int code() { | ||
return code; | ||
} | ||
|
||
public String stdout() { | ||
return stdout; | ||
} | ||
|
||
public String stderr() { | ||
return stderr; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CommandResult{" + | ||
"code=" + code + | ||
", stdout='" + stdout + '\'' + | ||
", stderr='" + stderr + '\'' + | ||
'}'; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
s3stream/src/main/java/com/automq/stream/utils/CommandUtils.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,39 @@ | ||
/* | ||
* 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 com.automq.stream.utils; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
|
||
public class CommandUtils { | ||
public CommandResult run(String... cmd) { | ||
try { | ||
Process p = Runtime.getRuntime().exec(cmd); | ||
try (BufferedReader inputReader = p.inputReader(); | ||
BufferedReader errorReader = p.errorReader()) { | ||
String stdout = String.join("\n", inputReader.lines().toList()); | ||
String stderr = String.join("\n", errorReader.lines().toList()); | ||
int code = p.waitFor(); | ||
return new CommandResult(code, stdout, stderr); | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
return new CommandResult(-1, "", e.getMessage()); | ||
} | ||
} | ||
|
||
} |
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