-
Notifications
You must be signed in to change notification settings - Fork 751
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
[GOBBLIN-1984] Add consensus flowExecutionId to FlowSpec to use for compilation #3857
Changes from 5 commits
8190591
6eaa5ca
70a2e64
465ed93
94a10fe
82fb861
ea8b1e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import com.linkedin.data.template.StringMap; | ||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
import com.typesafe.config.ConfigValueFactory; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
@@ -35,6 +36,7 @@ | |
import java.util.List; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
@@ -56,6 +58,7 @@ | |
* | ||
*/ | ||
@Alpha | ||
@AllArgsConstructor | ||
@Data | ||
@EqualsAndHashCode(exclude={"compilationErrors"}) | ||
@SuppressFBWarnings(value="SE_BAD_FIELD", | ||
|
@@ -75,13 +78,22 @@ public class FlowSpec implements Configurable, Spec { | |
/** Human-readable description of the flow spec */ | ||
final String description; | ||
|
||
/** Flow config as a typesafe config object */ | ||
final Config config; | ||
/* Note that since getConfig() and getConfigAsProperties() are independent accessors, `volatile` doesn't ensure a | ||
* consistent view between them. In a multi-threaded scenario one should use the following access mechanism: | ||
* FlowSpec fs = ... | ||
* synchronized (fs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggesting users to syncronized over the entire There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do agree it would be overkill in the general case, wherein the user is only getting one or the other of the two. there's no need for a single accessor to synchronize on the instance, given what I believe urmi's suggesting is to lock the object if one wants to access both. this ensures both sides agree. perhaps such clarification could be added to the comment:
? it sounds overly broad as phrased above, given "a MT scenario" applies to all our code everywhere. the other important thing to mention is that the the other alternative would be to add a combo method to this
would this perhaps be clearer, to provide a ready-made capability, rather than a long comment w/ usage advice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in fact, the new potential to mutate via as a reflection, there really is a lot to worry about once classes become mutable! although I see why it may be justified here, this complexity/headache is the reason I personally strive so hard to build immutable and state-less abstractions. (in the model, things can still change, but when they do, a new instance of a successor instance is created and the original remains safely unchanged.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the comment. I can add the combo method but it won't require access only through the combo method so I'd have to leave the comment in anyway. |
||
* fs.getConfig() | ||
* fs.getConfigAsProperties() | ||
* } | ||
*/ | ||
|
||
/** Flow config as a typesafe config object which can be replaced */ | ||
private volatile Config config; | ||
|
||
/** Flow config as a properties collection for backwards compatibility */ | ||
// Note that this property is not strictly necessary as it can be generated from the typesafe | ||
// config. We use it as a cache until typesafe config is more widely adopted in Gobblin. | ||
final Properties configAsProperties; | ||
private volatile Properties configAsProperties; | ||
|
||
/** URI of {@link org.apache.gobblin.runtime.api.JobTemplate} to use. */ | ||
final Optional<Set<URI>> templateURIs; | ||
|
@@ -125,6 +137,22 @@ public static FlowSpec.Builder builder(URI catalogURI, Properties flowProps) { | |
} | ||
} | ||
|
||
/** | ||
* Add property to Config (also propagated to the Properties field). These two fields should only be modified through | ||
* this method to prevent inconsistency between them. | ||
* @param key | ||
* @param value | ||
*/ | ||
public synchronized void addProperty(String key, String value) { | ||
this.config = config.withValue(key, ConfigValueFactory.fromAnyRef(value)); | ||
/* Make sure configAsProperties has been initialized. If it's just initialized, setting the property will be a | ||
redundant operation. However, if it already existed we need to update/add the key-value pair. | ||
*/ | ||
this.getConfigAsProperties(); | ||
this.configAsProperties.setProperty(key, value); | ||
|
||
} | ||
|
||
public void addCompilationError(String src, String dst, String errorMessage, int numberOfHops) { | ||
this.compilationErrors.add(new CompilationError(getConfig(), src, dst, errorMessage, numberOfHops)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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.runtime.api; | ||
|
||
import com.typesafe.config.Config; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Properties; | ||
import org.apache.gobblin.configuration.ConfigurationKeys; | ||
import org.apache.gobblin.service.FlowId; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class FlowSpecTest { | ||
|
||
/** | ||
* Tests that the addProperty() function to ensure the new flowSpec returned has the original properties and updated | ||
* ones | ||
* @throws URISyntaxException | ||
*/ | ||
@Test | ||
public void testAddProperty() throws URISyntaxException { | ||
String flowGroup = "myGroup"; | ||
String flowName = "myName"; | ||
String flowExecutionId = "1234"; | ||
FlowId flowId = new FlowId().setFlowGroup(flowGroup).setFlowName(flowName); | ||
URI flowUri = FlowSpec.Utils.createFlowSpecUri(flowId); | ||
|
||
// Create properties to be used as config | ||
Properties properties = new Properties(); | ||
properties.setProperty(ConfigurationKeys.FLOW_GROUP_KEY, flowGroup); | ||
properties.setProperty(ConfigurationKeys.FLOW_NAME_KEY, flowName); | ||
properties.setProperty(ConfigurationKeys.FLOW_IS_REMINDER_EVENT_KEY, "true"); | ||
|
||
FlowSpec flowSpec = FlowSpec.builder(flowUri).withConfigAsProperties(properties).build(); | ||
flowSpec.addProperty(ConfigurationKeys.FLOW_EXECUTION_ID_KEY, flowExecutionId); | ||
|
||
Properties updatedProperties = flowSpec.getConfigAsProperties(); | ||
Assert.assertEquals(updatedProperties.getProperty(ConfigurationKeys.FLOW_EXECUTION_ID_KEY), flowExecutionId); | ||
Assert.assertEquals(updatedProperties.getProperty(ConfigurationKeys.FLOW_GROUP_KEY), flowGroup); | ||
Assert.assertEquals(updatedProperties.getProperty(ConfigurationKeys.FLOW_NAME_KEY), flowName); | ||
Assert.assertEquals(updatedProperties.getProperty(ConfigurationKeys.FLOW_IS_REMINDER_EVENT_KEY), "true"); | ||
|
||
Config updatedConfig = flowSpec.getConfig(); | ||
Assert.assertEquals(updatedConfig.getString(ConfigurationKeys.FLOW_EXECUTION_ID_KEY), flowExecutionId); | ||
Assert.assertEquals(updatedConfig.getString(ConfigurationKeys.FLOW_GROUP_KEY), flowGroup); | ||
Assert.assertEquals(updatedConfig.getString(ConfigurationKeys.FLOW_NAME_KEY), flowName); | ||
Assert.assertEquals(updatedConfig.getString(ConfigurationKeys.FLOW_IS_REMINDER_EVENT_KEY), "true"); | ||
} | ||
} |
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.
change it to
Note that since getConfig() and getConfigAsProperties() are independent accessors, in a multi-threaded scenario one should use the following access mechanism:
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.
actually you can also provide a getMethod(), which will return only when
addProperty
is not being used. This way, users will not have to use syncronized