Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,58 @@
/*
* 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.gobblin.service.modules.dataset;

import com.google.common.base.Preconditions;
import com.typesafe.config.Config;
import java.io.IOException;
import java.util.ArrayList;
import lombok.Getter;
import org.apache.gobblin.service.modules.flowgraph.DatasetDescriptorConfigKeys;
import org.apache.gobblin.service.modules.flowgraph.DatasetDescriptorErrorUtils;
import org.apache.gobblin.util.ConfigUtils;


/**
* Describes a external dataset not on HDFS
* e.g, https://some-api:443/user/123/names where the path is the full URI
Comment thread
Will-Lo marked this conversation as resolved.
Outdated
*/
public class ExternalDatasetDescriptor extends BaseDatasetDescriptor implements DatasetDescriptor {

@Getter
private final String path;

public ExternalDatasetDescriptor(Config config) throws IOException {
super(config);
Preconditions.checkArgument(config.hasPath(DatasetDescriptorConfigKeys.PATH_KEY), "Dataset descriptor config must specify path");
// refers to the full HTTP url
this.path = ConfigUtils.getString(config, DatasetDescriptorConfigKeys.PATH_KEY, "");
Comment thread
Will-Lo marked this conversation as resolved.
Outdated
}

/**
* Check if this dataset descriptor is equivalent to another dataset descriptor
*
* @param inputDatasetDescriptorConfig whose path should be in the format of an external path (e.g. http url)
*/
@Override
protected ArrayList<String> isPathContaining(DatasetDescriptor inputDatasetDescriptorConfig) {
Comment thread
Will-Lo marked this conversation as resolved.
ArrayList<String> errors = new ArrayList<>();
String otherPath = inputDatasetDescriptorConfig.getPath();
DatasetDescriptorErrorUtils.populateErrorForDatasetDescriptorKey(errors, inputDatasetDescriptorConfig.getIsInputDataset(), DatasetDescriptorConfigKeys.PATH_KEY, this.getPath(), otherPath, false);
return errors;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.gobblin.service.modules.flowgraph.datanodes;

import com.typesafe.config.Config;
import org.apache.gobblin.service.modules.dataset.ExternalDatasetDescriptor;
import org.apache.gobblin.service.modules.flowgraph.BaseDataNode;


/**
* A DataNode for generic ingress/egress data movement outside of HDFS (HTTP or otherwise)
*/
public class ExternalDataNode extends BaseDataNode {
Comment thread
Will-Lo marked this conversation as resolved.
Outdated
public static final String EXTERNAL_PLATFORM_NAME = "external";
Comment thread
Will-Lo marked this conversation as resolved.
Outdated

public ExternalDataNode(Config nodeProps) throws DataNodeCreationException {
super(nodeProps);
}

@Override
public String getDefaultDatasetDescriptorPlatform() {
return EXTERNAL_PLATFORM_NAME;
}

@Override
public String getDefaultDatasetDescriptorClass() {
return ExternalDatasetDescriptor.class.getCanonicalName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.gobblin.service.modules.dataset;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValueFactory;
import java.io.IOException;
import org.apache.gobblin.service.modules.flowgraph.DatasetDescriptorConfigKeys;
import org.junit.Assert;
import org.testng.annotations.Test;


public class ExternalDatasetDescriptorTest {

@Test
public void testContains() throws IOException {
Config config1 = ConfigFactory.empty()
.withValue(DatasetDescriptorConfigKeys.PLATFORM_KEY, ConfigValueFactory.fromAnyRef("external"))
.withValue(DatasetDescriptorConfigKeys.PATH_KEY, ConfigValueFactory.fromAnyRef("https://a.com/b"));
ExternalDatasetDescriptor descriptor1 = new ExternalDatasetDescriptor(config1);

// Verify that same path points to same dataset
Config config2 = ConfigFactory.empty()
.withValue(DatasetDescriptorConfigKeys.PLATFORM_KEY, ConfigValueFactory.fromAnyRef("external"))
.withValue(DatasetDescriptorConfigKeys.PATH_KEY, ConfigValueFactory.fromAnyRef("https://a.com/b"));
ExternalDatasetDescriptor descriptor2 = new ExternalDatasetDescriptor(config2);
Assert.assertEquals(descriptor2.contains(descriptor1).size(), 0);
Comment thread
Will-Lo marked this conversation as resolved.

// Verify that different path points to different dataset
Config config3 = ConfigFactory.empty()
.withValue(DatasetDescriptorConfigKeys.PLATFORM_KEY, ConfigValueFactory.fromAnyRef("external"))
.withValue(DatasetDescriptorConfigKeys.PATH_KEY, ConfigValueFactory.fromAnyRef("https://a.com/c"));
ExternalDatasetDescriptor descriptor3 = new ExternalDatasetDescriptor(config3);
Assert.assertNotEquals(descriptor3.contains(descriptor1).size(), 0);

}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no biggie... but this probably ought to be ExternalUriDataNodeTest

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.gobblin.service.modules.flowgraph.datanodes;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValueFactory;
import org.apache.gobblin.service.modules.dataset.ExternalDatasetDescriptor;
import org.apache.gobblin.service.modules.flowgraph.DataNode;
import org.apache.gobblin.service.modules.flowgraph.FlowGraphConfigurationKeys;
import org.apache.gobblin.util.ConfigUtils;
import org.junit.Assert;
import org.testng.annotations.Test;


public class ExternalDataNodeTest {

@Test
public void testConfig() throws DataNode.DataNodeCreationException {
String expectedNodeId = "some-node-id";

Config config = ConfigFactory.empty()
.withValue(FlowGraphConfigurationKeys.DATA_NODE_ID_KEY, ConfigValueFactory.fromAnyRef(expectedNodeId));
ExternalDataNode node = new ExternalDataNode(config);

// Verify the node id
String id = node.getId();
Assert.assertEquals(id, expectedNodeId);
Assert.assertEquals(node.getDefaultDatasetDescriptorPlatform(), "external");
Assert.assertEquals(node.getDefaultDatasetDescriptorClass(), ExternalDatasetDescriptor.class.getCanonicalName());
}
}