-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BEAM-14081] [CdapIO] Add context classes for CDAP plugins #17104
Merged
chamikaramj
merged 37 commits into
apache:master
from
akvelon:BEAM-14081-context-wrapper
May 11, 2022
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
78dd87b
[BEAM-14048] Add ConfigWrapper for building CDAP PluginConfigs
Amar3tto 30b9e38
[BEAM-14048] Fix checkstyle
Amar3tto 9e5e6d6
[BEAM-14048] Fix warnings
Amar3tto 2d414f4
[BEAM-14048] Fix warnings
Amar3tto d35acb8
[BEAM-14048] Fix warning
Amar3tto b7e0fca
[BEAM-14048] Fix warning
Amar3tto 3252395
[BEAM-14048] Remove unused dependencies
Amar3tto f9e5675
[BEAM-14048] Add needed dependencies
Amar3tto 65a5442
[BEAM-14048] Fix spotless
Amar3tto 00aef64
[BEAM-14048] Fix typo
Amar3tto d10b84b
[BEAM-14048] Use fori instead of stream
Amar3tto 2f9686d
[BEAM-14048] Suppress warning
Amar3tto 119d2cc
[BEAM-14048] Add used undeclared artifacts
Amar3tto 1f63d65
[BEAM-14048] Change dependencies to test
Amar3tto 6207224
Add context.
8b5aecb
Merge branch 'BEAM-14048-cdap-config' into BEAM-14081-context-wrapper
1dbd4d6
Fix dependencies issue
0777205
Add null annotation
0645c7b
[BEAM-14048] Refactoring
Amar3tto 7251307
Add SuppressWarning.
dec0c3c
Fix style.
4cacd1c
Determine dependencies.
44125f0
Merge branch 'apache:master' into BEAM-14048-cdap-config
AKosolapov 8ba78c9
[BEAM-14048] Use CDAP InstantiatorFactory for creating config objects
Amar3tto 970fe79
[BEAM-14048] Suppress warning
Amar3tto 6b7549a
[BEAM-14081] Refactoring
Amar3tto d7d2042
Update maven repo
elizaveta-lomteva 129cffe
Update build.gradle
elizaveta-lomteva cc2cbcb
Merge branch 'BEAM-14048-cdap-config' into BEAM-14081-context-wrapper
Amar3tto 855122a
[BEAM-14081] Refactoring
Amar3tto f440da9
[BEAM-14048] Use ServiceNow CDAP dependency from Maven central
Amar3tto 7c0028c
Merge remote-tracking branch 'origin/BEAM-14048-cdap-config' into BEA…
Amar3tto 9df1c75
[BEAM-14048] Set macroFields
Amar3tto c5babc2
Merge branch 'BEAM-14048-cdap-config' into BEAM-14081-context-wrapper
Amar3tto 9701033
Merge branch 'master' into BEAM-14081-context-wrapper
Amar3tto 9e31a72
[BEAM-14081] Fix javadoc
Amar3tto 2f77cc4
[BEAM-14081] Make BatchContextImpl class abstract
Amar3tto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
232 changes: 232 additions & 0 deletions
232
sdks/java/io/cdap/src/main/java/org/apache/beam/sdk/io/cdap/context/BatchContextImpl.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,232 @@ | ||
/* | ||
* 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.beam.sdk.io.cdap.context; | ||
|
||
import io.cdap.cdap.api.data.DatasetInstantiationException; | ||
import io.cdap.cdap.api.data.batch.InputFormatProvider; | ||
import io.cdap.cdap.api.data.schema.Schema; | ||
import io.cdap.cdap.api.dataset.Dataset; | ||
import io.cdap.cdap.api.dataset.DatasetManagementException; | ||
import io.cdap.cdap.api.dataset.DatasetProperties; | ||
import io.cdap.cdap.api.metadata.Metadata; | ||
import io.cdap.cdap.api.metadata.MetadataEntity; | ||
import io.cdap.cdap.api.metadata.MetadataException; | ||
import io.cdap.cdap.api.metadata.MetadataScope; | ||
import io.cdap.cdap.api.plugin.PluginProperties; | ||
import io.cdap.cdap.etl.api.FailureCollector; | ||
import io.cdap.cdap.etl.api.Lookup; | ||
import io.cdap.cdap.etl.api.StageMetrics; | ||
import io.cdap.cdap.etl.api.SubmitterLifecycle; | ||
import io.cdap.cdap.etl.api.action.SettableArguments; | ||
import io.cdap.cdap.etl.api.batch.BatchContext; | ||
import io.cdap.cdap.etl.api.lineage.field.FieldOperation; | ||
import java.net.URL; | ||
import java.sql.Timestamp; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
|
||
/** Class for Batch, Sink and Stream CDAP wrapper classes that use it to provide common details. */ | ||
@SuppressWarnings({"TypeParameterUnusedInFormals", "nullness"}) | ||
public abstract class BatchContextImpl implements BatchContext { | ||
|
||
private final FailureCollectorWrapper failureCollector = new FailureCollectorWrapper(); | ||
|
||
/** | ||
* This should be set after {@link SubmitterLifecycle#prepareRun(Object)} call with passing this | ||
* context object as a param. | ||
*/ | ||
protected InputFormatProvider inputFormatProvider; | ||
|
||
private final Timestamp startTime = new Timestamp(System.currentTimeMillis()); | ||
|
||
public InputFormatProvider getInputFormatProvider() { | ||
return inputFormatProvider; | ||
} | ||
|
||
@Override | ||
public String getStageName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getNamespace() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPipelineName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public long getLogicalStartTime() { | ||
return this.startTime.getTime(); | ||
} | ||
|
||
@Override | ||
public StageMetrics getMetrics() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public PluginProperties getPluginProperties() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public PluginProperties getPluginProperties(String pluginId) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> Class<T> loadPluginClass(String pluginId) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> T newPluginInstance(String pluginId) throws InstantiationException { | ||
return null; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Schema getInputSchema() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public @Nullable Map<String, Schema> getInputSchemas() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public @Nullable Schema getOutputSchema() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Map<String, Schema> getOutputPortSchemas() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void createDataset(String datasetName, String typeName, DatasetProperties properties) | ||
throws DatasetManagementException {} | ||
|
||
@Override | ||
public boolean datasetExists(String datasetName) throws DatasetManagementException { | ||
return false; | ||
} | ||
|
||
@Override | ||
public SettableArguments getArguments() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public FailureCollector getFailureCollector() { | ||
return this.failureCollector; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public URL getServiceURL(String applicationId, String serviceId) { | ||
return null; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public URL getServiceURL(String serviceId) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Map<MetadataScope, Metadata> getMetadata(MetadataEntity metadataEntity) | ||
throws MetadataException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Metadata getMetadata(MetadataScope scope, MetadataEntity metadataEntity) | ||
throws MetadataException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void addProperties(MetadataEntity metadataEntity, Map<String, String> properties) {} | ||
|
||
@Override | ||
public void addTags(MetadataEntity metadataEntity, String... tags) {} | ||
|
||
@Override | ||
public void addTags(MetadataEntity metadataEntity, Iterable<String> tags) {} | ||
|
||
@Override | ||
public void removeMetadata(MetadataEntity metadataEntity) {} | ||
|
||
@Override | ||
public void removeProperties(MetadataEntity metadataEntity) {} | ||
|
||
@Override | ||
public void removeProperties(MetadataEntity metadataEntity, String... keys) {} | ||
|
||
@Override | ||
public void removeTags(MetadataEntity metadataEntity) {} | ||
|
||
@Override | ||
public void removeTags(MetadataEntity metadataEntity, String... tags) {} | ||
|
||
@Override | ||
public void record(List<FieldOperation> fieldOperations) {} | ||
|
||
@Override | ||
public <T extends Dataset> T getDataset(String name) throws DatasetInstantiationException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T extends Dataset> T getDataset(String namespace, String name) | ||
throws DatasetInstantiationException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T extends Dataset> T getDataset(String name, Map<String, String> arguments) | ||
throws DatasetInstantiationException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T extends Dataset> T getDataset( | ||
String namespace, String name, Map<String, String> arguments) | ||
throws DatasetInstantiationException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void releaseDataset(Dataset dataset) {} | ||
|
||
@Override | ||
public void discardDataset(Dataset dataset) {} | ||
|
||
@Override | ||
public <T> Lookup<T> provide(String table, Map<String, String> arguments) { | ||
return null; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../java/io/cdap/src/main/java/org/apache/beam/sdk/io/cdap/context/BatchSinkContextImpl.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,33 @@ | ||
/* | ||
* 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.beam.sdk.io.cdap.context; | ||
|
||
import io.cdap.cdap.api.data.batch.Output; | ||
import io.cdap.cdap.etl.api.batch.BatchSinkContext; | ||
|
||
/** Class for creating context object of different CDAP classes with batch sink type. */ | ||
public class BatchSinkContextImpl extends BatchContextImpl implements BatchSinkContext { | ||
|
||
@Override | ||
public void addOutput(Output output) {} | ||
|
||
@Override | ||
public boolean isPreviewEnabled() { | ||
return false; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ava/io/cdap/src/main/java/org/apache/beam/sdk/io/cdap/context/BatchSourceContextImpl.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,40 @@ | ||
/* | ||
* 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.beam.sdk.io.cdap.context; | ||
|
||
import io.cdap.cdap.api.data.batch.Input; | ||
import io.cdap.cdap.etl.api.batch.BatchSourceContext; | ||
|
||
/** Class for creating context object of different CDAP classes with batch source type. */ | ||
public class BatchSourceContextImpl extends BatchContextImpl implements BatchSourceContext { | ||
|
||
@Override | ||
public void setInput(Input input) { | ||
this.inputFormatProvider = ((Input.InputFormatProviderInput) input).getInputFormatProvider(); | ||
} | ||
|
||
@Override | ||
public boolean isPreviewEnabled() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getMaxPreviewRecords() { | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these methods be implemented ? What does the default implementation that mostly return null provide ? If this class is not usable as is can we make it an abstract class ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, this class only provides
FailureCollectorWrapper
and stubs all other methods as they are only needed for the CDAP environment.Yes, it can be abstract, because we are only supposed to create objects of its child classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done