/*
 * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed 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 com.hazelcast.jet;

import com.hazelcast.core.Cluster;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.jet.config.JetConfig;
import com.hazelcast.jet.config.JobConfig;
import com.hazelcast.jet.core.DAG;
import com.hazelcast.jet.stream.IStreamList;
import com.hazelcast.jet.stream.IStreamMap;
import com.hazelcast.jet.stream.JetCacheManager;

import java.util.Collection;

/**
 * Represents either an instance of a Jet server node or a Jet client
 * instance that connects to a remote cluster.
 */
public interface JetInstance {

    /**
     * Returns the name of the Jet instance.
     */
    String getName();

    /**
     * Returns the underlying Hazelcast IMDG instance used by Jet. It will
     * be either a server node or a client, depending on the type of this
     * {@code JetInstance}.
     */
    HazelcastInstance getHazelcastInstance();

    /**
     * Returns information about the cluster this Jet instance is part of.
     */
    Cluster getCluster();

    /**
     * Returns the configuration for this Jet member. This method is not
     * available on client instances.
     */
    JetConfig getConfig();

    /**
     * Creates and returns an executable job based on a given DAG.
     *
     * @param dag The DAG that will be used to for the execution of the job
     * @return a new {@link Job} instance
     */
    Job newJob(DAG dag);

    /**
     * Creates and returns an executable Job based on the supplied DAG and job
     * configuration.
     *
     * @return a new {@code Job} instance
     */
    Job newJob(DAG dag, JobConfig config);

    /**
     * Returns all submitted jobs including running and completed ones
     */
    Collection<Job> getJobs();

    /**
     * Returns the distributed map instance with the specified name.
     *
     * @param name name of the distributed map
     * @return distributed map instance with the specified name
     */
    <K, V> IStreamMap<K, V> getMap(String name);

    /**
     * Returns the distributed list instance with the specified name.
     * Index-based operations on the list are not supported.
     *
     * @param name name of the distributed list
     * @return distributed list instance with the specified name
     */
    <E> IStreamList<E> getList(String name);

    /**
     * Obtain the {@link JetCacheManager} that provides access to JSR-107 (JCache) caches
     * configured on a Hazelcast Jet cluster.
     * <p>
     * Note that this method does not return a JCache {@code CacheManager}
     *
     * @return the Hazelcast Jet {@link JetCacheManager}
     * @see JetCacheManager
     */
    JetCacheManager getCacheManager();

    /**
     * Shutdowns the current instance.
     */
    void shutdown();

}

@@ -1808,28 +1808,20 @@
 eturns a
-n executable
+ Jet
  job bas
@@ -1830,145 +1830,265 @@
  on 
-a given DAG.%0A     *%0A     * @param dag The DAG that will be used to for the execution of the job%0A     * @return a new %7B@link Job%7D instance
+the supplied DAG. Jet will%0A     * asynchronously start executing the job.%0A     */%0A    Job newJob(DAG dag);%0A%0A    /**%0A     * Creates and returns a Jet job based on the supplied DAG and job%0A     * configuration. Jet will asynchronously start executing the job.
 %0A   
@@ -2106,32 +2106,50 @@
 b newJob(DAG dag
+, JobConfig config
 );%0A%0A    /**%0A    
@@ -2185,17 +2185,17 @@
 cutable 
-J
+j
 ob based
@@ -2215,90 +2215,328 @@
 ied 
-DAG and
+pipeline.%0A     * Jet will asynchronously start executing the
  job
+.
 %0A     *
- configuration.%0A     *%0A     * @
+/%0A    default Job newJob(Pipeline pipeline) %7B%0A        return newJob(pipeline.toDag());%0A    %7D%0A%0A    /**%0A     * Creates and 
 return
+s
  a 
-new %7B@code Job%7D instance
+Jet job based on the supplied pipeline and job%0A     * configuration. Jet will asynchronously start executing the job.
 %0A   
@@ -2536,32 +2536,40 @@
 ob.%0A     */%0A    
+default 
 Job newJob(DAG d
@@ -2555,39 +2555,49 @@
 ault Job newJob(
-DAG dag
+Pipeline pipeline
 , JobConfig conf
@@ -2591,33 +2591,89 @@
 obConfig config)
-;
+ %7B%0A        return newJob(pipeline.toDag(), config);%0A    %7D
 %0A%0A    /**%0A     *

align API to start job from DAG or pipeline