Skip to content
Closed
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
25 changes: 25 additions & 0 deletions hadoop-ozone/objectstore-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@

import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdfs.server.datanode.ObjectStoreHandler;
import org.apache.hadoop.ozone.HddsDatanodeService;
import org.apache.hadoop.ozone.web.netty.ObjectStoreRestHttpServer;

import org.apache.commons.io.IOUtils;
import org.apache.hadoop.util.ServicePlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.annotations.VisibleForTesting;

/**
* DataNode service plugin implementation to start ObjectStore rest server.
*/
Expand All @@ -49,12 +50,12 @@ public void start(Object service) {
HddsDatanodeService hddsDatanodeService = (HddsDatanodeService) service;
conf = hddsDatanodeService.getConf();
handler = new ObjectStoreHandler(conf);
objectStoreRestHttpServer = new ObjectStoreRestHttpServer(
conf, null, handler);
objectStoreRestHttpServer =
new ObjectStoreRestHttpServer(conf, null, handler);
objectStoreRestHttpServer.start();
DatanodeDetails.Port restPort = DatanodeDetails.newPort(
DatanodeDetails.Port.Name.REST,
objectStoreRestHttpServer.getHttpAddress().getPort());
DatanodeDetails.Port restPort =
DatanodeDetails.newPort(DatanodeDetails.Port.Name.REST,
objectStoreRestHttpServer.getHttpAddress().getPort());
hddsDatanodeService.getDatanodeDetails().setPort(restPort);

} catch (IOException e) {
Expand All @@ -68,7 +69,6 @@ public void start(Object service) {
}
}


@Override
public void stop() {
try {
Expand All @@ -86,4 +86,13 @@ public void close() {
IOUtils.closeQuietly(handler);
}

@VisibleForTesting
public ObjectStoreHandler getHandler() {
return handler;
}

@VisibleForTesting
public ObjectStoreRestHttpServer getObjectStoreRestHttpServer() {
return objectStoreRestHttpServer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* 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.web;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.ozone.HddsDatanodeService;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import com.google.protobuf.Service;

/**
* Test class for {@link OzoneHddsDatanodeService}.
*/
public class TestOzoneHddsDatanodeService {
private File testDir;
private OzoneConfiguration conf;

@Before
public void setUp() {
testDir = GenericTestUtils.getRandomizedTestDir();
String volumeDir = testDir + "/disk1";

conf = new OzoneConfiguration();
conf.set(ScmConfigKeys.OZONE_SCM_NAMES, "localhost");
conf.setBoolean(OzoneConfigKeys.OZONE_ENABLED, true);
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getPath());
conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, volumeDir);
}

@After
public void tearDown() {
FileUtil.fullyDelete(testDir);
}

@Test
public void testStartup() throws IOException {
OzoneHddsDatanodeService ozoneHddsService = new OzoneHddsDatanodeService();
String[] args = new String[] {};
HddsDatanodeService hddsServiceSpy =
Mockito.spy(HddsDatanodeService.createHddsDatanodeService(args));
hddsServiceSpy.setConfiguration(conf);

DatanodeDetails.Builder builder = DatanodeDetails.newBuilder();
builder.setUuid(UUID.randomUUID().toString());
DatanodeDetails datanodeDetails = builder.build();
Mockito.doReturn(datanodeDetails).when(hddsServiceSpy).getDatanodeDetails();

ozoneHddsService.start(hddsServiceSpy);

assertNotNull(ozoneHddsService.getHandler());
assertNotNull(ozoneHddsService.getObjectStoreRestHttpServer());

ozoneHddsService.close();
}

@Test
public void testStartupFail() throws IOException {
OzoneHddsDatanodeService ozoneHddsService = new OzoneHddsDatanodeService();
Service mockService = mock(Service.class);
ozoneHddsService.start(mockService);

assertNull(ozoneHddsService.getHandler());
assertNull(ozoneHddsService.getObjectStoreRestHttpServer());

ozoneHddsService.close();
}
}