Search in sources :

Example 6 with ConfigException

use of com.typesafe.config.ConfigException in project config by typesafehub.

the class ConfigReference method resolveSubstitutions.

// ConfigReference should be a firewall against NotPossibleToResolve going
// further up the stack; it should convert everything to ConfigException.
// This way it's impossible for NotPossibleToResolve to "escape" since
// any failure to resolve has to start with a ConfigReference.
@Override
ResolveResult<? extends AbstractConfigValue> resolveSubstitutions(ResolveContext context, ResolveSource source) {
    ResolveContext newContext = context.addCycleMarker(this);
    AbstractConfigValue v;
    try {
        ResolveSource.ResultWithPath resultWithPath = source.lookupSubst(newContext, expr, prefixLength);
        newContext = resultWithPath.result.context;
        if (resultWithPath.result.value != null) {
            if (ConfigImpl.traceSubstitutionsEnabled())
                ConfigImpl.trace(newContext.depth(), "recursively resolving " + resultWithPath + " which was the resolution of " + expr + " against " + source);
            ResolveSource recursiveResolveSource = (new ResolveSource((AbstractConfigObject) resultWithPath.pathFromRoot.last(), resultWithPath.pathFromRoot));
            if (ConfigImpl.traceSubstitutionsEnabled())
                ConfigImpl.trace(newContext.depth(), "will recursively resolve against " + recursiveResolveSource);
            ResolveResult<? extends AbstractConfigValue> result = newContext.resolve(resultWithPath.result.value, recursiveResolveSource);
            v = result.value;
            newContext = result.context;
        } else {
            ConfigValue fallback = context.options().getResolver().lookup(expr.path().render());
            v = (AbstractConfigValue) fallback;
        }
    } catch (NotPossibleToResolve e) {
        if (ConfigImpl.traceSubstitutionsEnabled())
            ConfigImpl.trace(newContext.depth(), "not possible to resolve " + expr + ", cycle involved: " + e.traceString());
        if (expr.optional())
            v = null;
        else
            throw new ConfigException.UnresolvedSubstitution(origin(), expr + " was part of a cycle of substitutions involving " + e.traceString(), e);
    }
    if (v == null && !expr.optional()) {
        if (newContext.options().getAllowUnresolved())
            return ResolveResult.make(newContext.removeCycleMarker(this), this);
        else
            throw new ConfigException.UnresolvedSubstitution(origin(), expr.toString());
    } else {
        return ResolveResult.make(newContext.removeCycleMarker(this), v);
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) ConfigException(com.typesafe.config.ConfigException)

Example 7 with ConfigException

use of com.typesafe.config.ConfigException in project incubator-gobblin by apache.

the class R2ClientFactoryTest method testHttpClient.

public void testHttpClient() {
    R2ClientFactory factory = new R2ClientFactory(R2ClientFactory.Schema.HTTP);
    Map<String, Object> values = new HashMap<>();
    // No SSL
    Client client = factory.createInstance(ConfigFactory.parseMap(values));
    shutdown(client);
    // With SSL
    values.put(R2ClientFactory.SSL_ENABLED, true);
    values.put(SSLContextFactory.KEY_STORE_FILE_PATH, "identity.p12");
    values.put(SSLContextFactory.TRUST_STORE_FILE_PATH, "certs");
    values.put(SSLContextFactory.KEY_STORE_PASSWORD, "keyStorePassword");
    values.put(SSLContextFactory.TRUST_STORE_PASSWORD, "trustStorePassword");
    values.put(SSLContextFactory.KEY_STORE_TYPE, "PKCS12");
    try {
        factory.createInstance(ConfigFactory.parseMap(values));
    } catch (ConfigException | IllegalArgumentException e) {
        Assert.fail();
    } catch (Exception e) {
    // OK
    }
}
Also used : HashMap(java.util.HashMap) ConfigException(com.typesafe.config.ConfigException) Client(com.linkedin.r2.transport.common.Client) ExecutionException(java.util.concurrent.ExecutionException) ConfigException(com.typesafe.config.ConfigException)

Example 8 with ConfigException

use of com.typesafe.config.ConfigException in project incubator-gobblin by apache.

the class R2ClientFactoryTest method testD2Client.

public void testD2Client() throws Exception {
    R2ClientFactory factory = new R2ClientFactory(R2ClientFactory.Schema.D2);
    TestingServer zkServer = new TestingServer(-1);
    Map<String, Object> values = new HashMap<>();
    values.put("d2.zkHosts", zkServer.getConnectString());
    // No SSL
    Client client = factory.createInstance(ConfigFactory.parseMap(values));
    shutdown(client);
    // With SSL
    final String confPrefix = "d2.";
    values.put(confPrefix + R2ClientFactory.SSL_ENABLED, true);
    values.put(confPrefix + SSLContextFactory.KEY_STORE_FILE_PATH, "identity.p12");
    values.put(confPrefix + SSLContextFactory.TRUST_STORE_FILE_PATH, "certs");
    values.put(confPrefix + SSLContextFactory.KEY_STORE_PASSWORD, "keyStorePassword");
    values.put(confPrefix + SSLContextFactory.TRUST_STORE_PASSWORD, "trustStorePassword");
    values.put(confPrefix + SSLContextFactory.KEY_STORE_TYPE, "PKCS12");
    try {
        factory.createInstance(ConfigFactory.parseMap(values));
    } catch (ConfigException | IllegalArgumentException e) {
        Assert.fail("Unexpected config exception");
    } catch (Exception e) {
    // OK
    }
    zkServer.close();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) HashMap(java.util.HashMap) ConfigException(com.typesafe.config.ConfigException) Client(com.linkedin.r2.transport.common.Client) ExecutionException(java.util.concurrent.ExecutionException) ConfigException(com.typesafe.config.ConfigException)

Example 9 with ConfigException

use of com.typesafe.config.ConfigException in project incubator-gobblin by apache.

the class StaticFlowTemplate method getDatasetDescriptors.

/**
 * Generate the input/output dataset descriptors for the {@link FlowTemplate}.
 * @param userConfig User supplied Config
 * @param resolvable Whether to return only resolvable dataset descriptors
 * @return a List of Input/Output DatasetDescriptors that correspond to this {@link FlowTemplate}. If resolvable is true,
 * only return descriptors that fully resolve it.
 */
@Override
public List<Pair<DatasetDescriptor, DatasetDescriptor>> getDatasetDescriptors(Config userConfig, boolean resolvable) throws IOException {
    Config config = this.getResolvedFlowConfig(userConfig).resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true));
    if (!config.hasPath(DatasetDescriptorConfigKeys.FLOW_EDGE_INPUT_DATASET_DESCRIPTOR_PREFIX) || !config.hasPath(DatasetDescriptorConfigKeys.FLOW_EDGE_OUTPUT_DATASET_DESCRIPTOR_PREFIX)) {
        throw new IOException("Flow template must specify at least one input/output dataset descriptor");
    }
    int i = 0;
    String inputPrefix = Joiner.on(".").join(DatasetDescriptorConfigKeys.FLOW_EDGE_INPUT_DATASET_DESCRIPTOR_PREFIX, Integer.toString(i));
    List<Pair<DatasetDescriptor, DatasetDescriptor>> result = Lists.newArrayList();
    while (config.hasPath(inputPrefix)) {
        try {
            Config inputDescriptorConfig = config.getConfig(inputPrefix);
            DatasetDescriptor inputDescriptor = DatasetDescriptorUtils.constructDatasetDescriptor(inputDescriptorConfig);
            String outputPrefix = Joiner.on(".").join(DatasetDescriptorConfigKeys.FLOW_EDGE_OUTPUT_DATASET_DESCRIPTOR_PREFIX, Integer.toString(i));
            Config outputDescriptorConfig = config.getConfig(outputPrefix);
            DatasetDescriptor outputDescriptor = DatasetDescriptorUtils.constructDatasetDescriptor(outputDescriptorConfig);
            if (resolvable) {
                try {
                    tryResolving(userConfig, inputDescriptor, outputDescriptor);
                    result.add(ImmutablePair.of(inputDescriptor, outputDescriptor));
                } catch (JobTemplate.TemplateException | ConfigException | SpecNotFoundException e) {
                // Dataset descriptor cannot be resolved so don't add it to result
                }
            } else {
                result.add(ImmutablePair.of(inputDescriptor, outputDescriptor));
            }
        } catch (ReflectiveOperationException e) {
        // Cannot instantiate I/O dataset descriptor due to missing config; skip and try the next one.
        }
        inputPrefix = Joiner.on(".").join(DatasetDescriptorConfigKeys.FLOW_EDGE_INPUT_DATASET_DESCRIPTOR_PREFIX, Integer.toString(++i));
    }
    return result;
}
Also used : DatasetDescriptor(org.apache.gobblin.service.modules.dataset.DatasetDescriptor) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) Config(com.typesafe.config.Config) ConfigException(com.typesafe.config.ConfigException) IOException(java.io.IOException) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 10 with ConfigException

use of com.typesafe.config.ConfigException in project incubator-gobblin by apache.

the class AbstractPathFinder method getNextEdges.

/**
 * A helper method that sorts the {@link FlowEdge}s incident on srcNode based on whether the FlowEdge has an
 * output {@link DatasetDescriptor} that is compatible with the targetDatasetDescriptor.
 * @param dataNode the {@link DataNode} to be expanded for determining candidate edges.
 * @param currentDatasetDescriptor Output {@link DatasetDescriptor} of the current edge.
 * @param destDatasetDescriptor Target {@link DatasetDescriptor}.
 * @return prioritized list of {@link FlowEdge}s to be added to the edge queue for expansion.
 */
List<FlowEdgeContext> getNextEdges(DataNode dataNode, DatasetDescriptor currentDatasetDescriptor, DatasetDescriptor destDatasetDescriptor) {
    List<FlowEdgeContext> prioritizedEdgeList = new LinkedList<>();
    List<String> edgeIds = ConfigUtils.getStringList(this.flowConfig, ConfigurationKeys.WHITELISTED_EDGE_IDS);
    for (FlowEdge flowEdge : this.flowGraph.getEdges(dataNode)) {
        if (!edgeIds.isEmpty() && !edgeIds.contains(flowEdge.getId())) {
            continue;
        }
        try {
            DataNode edgeDestination = this.flowGraph.getNode(flowEdge.getDest());
            // Base condition: Skip this FLowEdge, if it is inactive or if the destination of this edge is inactive.
            if (!edgeDestination.isActive() || !flowEdge.isActive()) {
                continue;
            }
            boolean foundExecutor = false;
            // Iterate over all executors for this edge. Find the first one that resolves the underlying flow template.
            for (SpecExecutor specExecutor : flowEdge.getExecutors()) {
                Config mergedConfig = getMergedConfig(flowEdge);
                List<Pair<DatasetDescriptor, DatasetDescriptor>> datasetDescriptorPairs = flowEdge.getFlowTemplate().getDatasetDescriptors(mergedConfig, false);
                for (Pair<DatasetDescriptor, DatasetDescriptor> datasetDescriptorPair : datasetDescriptorPairs) {
                    DatasetDescriptor inputDatasetDescriptor = datasetDescriptorPair.getLeft();
                    DatasetDescriptor outputDatasetDescriptor = datasetDescriptorPair.getRight();
                    try {
                        flowEdge.getFlowTemplate().tryResolving(mergedConfig, datasetDescriptorPair.getLeft(), datasetDescriptorPair.getRight());
                    } catch (JobTemplate.TemplateException | ConfigException | SpecNotFoundException e) {
                        flowSpec.addCompilationError(flowEdge.getSrc(), flowEdge.getDest(), "Error compiling edge " + flowEdge.toString() + ": " + e.toString());
                        continue;
                    }
                    if (inputDatasetDescriptor.contains(currentDatasetDescriptor)) {
                        DatasetDescriptor edgeOutputDescriptor = makeOutputDescriptorSpecific(currentDatasetDescriptor, outputDatasetDescriptor);
                        FlowEdgeContext flowEdgeContext = new FlowEdgeContext(flowEdge, currentDatasetDescriptor, edgeOutputDescriptor, mergedConfig, specExecutor);
                        if (destDatasetDescriptor.getFormatConfig().contains(outputDatasetDescriptor.getFormatConfig())) {
                            /*
                Add to the front of the edge list if platform-independent properties of the output descriptor is compatible
                with those of destination dataset descriptor.
                In other words, we prioritize edges that perform data transformations as close to the source as possible.
                */
                            prioritizedEdgeList.add(0, flowEdgeContext);
                        } else {
                            prioritizedEdgeList.add(flowEdgeContext);
                        }
                        foundExecutor = true;
                    }
                }
                // TODO: Choose the min-cost executor for the FlowEdge as opposed to the first one that resolves.
                if (foundExecutor) {
                    break;
                }
            }
        } catch (IOException | ReflectiveOperationException | SpecNotFoundException | JobTemplate.TemplateException e) {
            // Skip the edge; and continue
            log.warn("Skipping edge {} with config {} due to exception: {}", flowEdge.getId(), flowConfig.toString(), e);
        }
    }
    return prioritizedEdgeList;
}
Also used : FlowEdge(org.apache.gobblin.service.modules.flowgraph.FlowEdge) DatasetDescriptor(org.apache.gobblin.service.modules.dataset.DatasetDescriptor) Config(com.typesafe.config.Config) ConfigException(com.typesafe.config.ConfigException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) FlowEdgeContext(org.apache.gobblin.service.modules.flow.FlowEdgeContext) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) DataNode(org.apache.gobblin.service.modules.flowgraph.DataNode) SpecExecutor(org.apache.gobblin.runtime.api.SpecExecutor) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ConfigException (com.typesafe.config.ConfigException)10 Config (com.typesafe.config.Config)4 HoconTreeTraversingParser (com.jasonclawson.jackson.dataformat.hocon.HoconTreeTraversingParser)2 Client (com.linkedin.r2.transport.common.Client)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 Pair (org.apache.commons.lang3.tuple.Pair)2 SpecNotFoundException (org.apache.gobblin.runtime.api.SpecNotFoundException)2 DatasetDescriptor (org.apache.gobblin.service.modules.dataset.DatasetDescriptor)2 ConfigParseOptions (com.typesafe.config.ConfigParseOptions)1 ConfigValue (com.typesafe.config.ConfigValue)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ChronoUnit (java.time.temporal.ChronoUnit)1 LinkedList (java.util.LinkedList)1 TimeUnit (java.util.concurrent.TimeUnit)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 TestingServer (org.apache.curator.test.TestingServer)1 SpecExecutor (org.apache.gobblin.runtime.api.SpecExecutor)1