Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 org.apache.hadoop.ozone.local;

/**
* Runtime contract for local single-node Ozone commands.
*/
public interface LocalOzoneRuntime extends AutoCloseable {

void start() throws Exception;

String getDisplayHost();

int getScmPort();

int getOmPort();

int getS3gPort();

String getS3Endpoint();

@Override
void close() throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.hadoop.ozone.local;

import java.util.concurrent.Callable;
import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import picocli.CommandLine.Command;

/**
* Internal CLI entry point for local single-node Ozone commands.
*/
@Command(name = "ozone local",
hidden = true,
description = "Internal commands for local single-node Ozone",
versionProvider = HddsVersionProvider.class,
mixinStandardHelpOptions = true,
subcommands = {
OzoneLocal.RunCommand.class
})
public class OzoneLocal extends GenericCli {

public static void main(String[] args) {
new OzoneLocal().run(args);
}

@Command(name = "run",
hidden = true,
description = "Internal placeholder for a local Ozone runtime")
static class RunCommand implements Callable<Void> {

@Override
public Void call() {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

/**
* Internal local single-node Ozone runtime support.
*/
package org.apache.hadoop.ozone.local;
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.hadoop.ozone.local;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
import picocli.CommandLine.Command;

/**
* Tests for {@link OzoneLocal}.
*/
class TestOzoneLocal {

@Test
void localCommandMetadataIsPresentAndHidden() {
Command command = OzoneLocal.class.getAnnotation(Command.class);

assertNotNull(command);
assertEquals("ozone local", command.name());
assertTrue(command.hidden());
}

@Test
void runCommandMetadataIsPresentAndHidden() {
Command command = OzoneLocal.RunCommand.class.getAnnotation(Command.class);

assertNotNull(command);
assertEquals("run", command.name());
assertTrue(command.hidden());
}

@Test
void genericCliRegistersRunPlaceholder() {
OzoneLocal local = new OzoneLocal();

assertTrue(local.getCmd().getSubcommands().containsKey("run"));
}

@Test
void rootHelpHidesRunPlaceholder() throws Exception {
OzoneLocal local = new OzoneLocal();
CommandLine commandLine = local.getCmd();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
commandLine.setOut(new PrintWriter(new OutputStreamWriter(out, UTF_8),
true));
commandLine.setErr(new PrintWriter(new OutputStreamWriter(err, UTF_8),
true));

int exitCode = local.execute(new String[] {"--help"});

String help = out.toString(UTF_8.name());
assertEquals(0, exitCode);
assertTrue(help.contains("Usage: ozone local"));
assertFalse(help.contains("run"));
Comment thread
henrybear327 marked this conversation as resolved.
assertEquals("", err.toString(UTF_8.name()));
}

@Test
void runCommandIsQuietNoOpPlaceholder() throws Exception {
OzoneLocal local = new OzoneLocal();
CommandLine commandLine = local.getCmd();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
commandLine.setOut(new PrintWriter(new OutputStreamWriter(out, UTF_8),
true));
commandLine.setErr(new PrintWriter(new OutputStreamWriter(err, UTF_8),
true));

int exitCode = local.execute(new String[] {"run"});

assertEquals(0, exitCode);
assertEquals("", out.toString(UTF_8.name()));
assertEquals("", err.toString(UTF_8.name()));
}
}