Skip to content

Commit d85b05a

Browse files
authored
HDDS-15081. Add Internal Scaffold (#10146)
1 parent bc54891 commit d85b05a

4 files changed

Lines changed: 212 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.local;
19+
20+
/**
21+
* Runtime contract for local single-node Ozone commands.
22+
*/
23+
public interface LocalOzoneRuntime extends AutoCloseable {
24+
25+
void start() throws Exception;
26+
27+
String getDisplayHost();
28+
29+
int getScmPort();
30+
31+
int getOmPort();
32+
33+
int getS3gPort();
34+
35+
String getS3Endpoint();
36+
37+
@Override
38+
void close() throws Exception;
39+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.local;
19+
20+
import java.util.concurrent.Callable;
21+
import org.apache.hadoop.hdds.cli.GenericCli;
22+
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
23+
import picocli.CommandLine.Command;
24+
25+
/**
26+
* Internal CLI entry point for local single-node Ozone commands.
27+
*/
28+
@Command(name = "ozone local",
29+
hidden = true,
30+
description = "Internal commands for local single-node Ozone",
31+
versionProvider = HddsVersionProvider.class,
32+
mixinStandardHelpOptions = true,
33+
subcommands = {
34+
OzoneLocal.RunCommand.class
35+
})
36+
public class OzoneLocal extends GenericCli {
37+
38+
public static void main(String[] args) {
39+
new OzoneLocal().run(args);
40+
}
41+
42+
@Command(name = "run",
43+
hidden = true,
44+
description = "Internal placeholder for a local Ozone runtime")
45+
static class RunCommand implements Callable<Void> {
46+
47+
@Override
48+
public Void call() {
49+
return null;
50+
}
51+
}
52+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* Internal local single-node Ozone runtime support.
20+
*/
21+
package org.apache.hadoop.ozone.local;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.local;
19+
20+
import static java.nio.charset.StandardCharsets.UTF_8;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
26+
import java.io.ByteArrayOutputStream;
27+
import java.io.OutputStreamWriter;
28+
import java.io.PrintWriter;
29+
import org.junit.jupiter.api.Test;
30+
import picocli.CommandLine;
31+
import picocli.CommandLine.Command;
32+
33+
/**
34+
* Tests for {@link OzoneLocal}.
35+
*/
36+
class TestOzoneLocal {
37+
38+
@Test
39+
void localCommandMetadataIsPresentAndHidden() {
40+
Command command = OzoneLocal.class.getAnnotation(Command.class);
41+
42+
assertNotNull(command);
43+
assertEquals("ozone local", command.name());
44+
assertTrue(command.hidden());
45+
}
46+
47+
@Test
48+
void runCommandMetadataIsPresentAndHidden() {
49+
Command command = OzoneLocal.RunCommand.class.getAnnotation(Command.class);
50+
51+
assertNotNull(command);
52+
assertEquals("run", command.name());
53+
assertTrue(command.hidden());
54+
}
55+
56+
@Test
57+
void genericCliRegistersRunPlaceholder() {
58+
OzoneLocal local = new OzoneLocal();
59+
60+
assertTrue(local.getCmd().getSubcommands().containsKey("run"));
61+
}
62+
63+
@Test
64+
void rootHelpHidesRunPlaceholder() throws Exception {
65+
OzoneLocal local = new OzoneLocal();
66+
CommandLine commandLine = local.getCmd();
67+
ByteArrayOutputStream out = new ByteArrayOutputStream();
68+
ByteArrayOutputStream err = new ByteArrayOutputStream();
69+
commandLine.setOut(new PrintWriter(new OutputStreamWriter(out, UTF_8),
70+
true));
71+
commandLine.setErr(new PrintWriter(new OutputStreamWriter(err, UTF_8),
72+
true));
73+
74+
int exitCode = local.execute(new String[] {"--help"});
75+
76+
String help = out.toString(UTF_8.name());
77+
assertEquals(0, exitCode);
78+
assertTrue(help.contains("Usage: ozone local"));
79+
assertFalse(help.contains("run"));
80+
assertEquals("", err.toString(UTF_8.name()));
81+
}
82+
83+
@Test
84+
void runCommandIsQuietNoOpPlaceholder() throws Exception {
85+
OzoneLocal local = new OzoneLocal();
86+
CommandLine commandLine = local.getCmd();
87+
ByteArrayOutputStream out = new ByteArrayOutputStream();
88+
ByteArrayOutputStream err = new ByteArrayOutputStream();
89+
commandLine.setOut(new PrintWriter(new OutputStreamWriter(out, UTF_8),
90+
true));
91+
commandLine.setErr(new PrintWriter(new OutputStreamWriter(err, UTF_8),
92+
true));
93+
94+
int exitCode = local.execute(new String[] {"run"});
95+
96+
assertEquals(0, exitCode);
97+
assertEquals("", out.toString(UTF_8.name()));
98+
assertEquals("", err.toString(UTF_8.name()));
99+
}
100+
}

0 commit comments

Comments
 (0)