// Path: smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletFactory.java
// public class CmdletFactory {
//   static final Logger LOG = LoggerFactory.getLogger(CmdletFactory.class);
//   private final SmartContext smartContext;
//   private final StatusReporter reporter;
// 
//   public CmdletFactory(SmartContext smartContext) {
//     this(smartContext, null);
//   }
// 
//   public CmdletFactory(SmartContext smartContext, StatusReporter reporter) {
//     this.smartContext = smartContext;
//     this.reporter = reporter;
//   }
// 
//   public Cmdlet createCmdlet(LaunchCmdlet launchCmdlet) throws ActionException {
//     List<SmartAction> actions = new ArrayList<>();
//     int idx = 0;
//     for (LaunchAction action : launchCmdlet.getLaunchActions()) {
//       idx++;
//       actions.add(createAction(launchCmdlet.getCmdletId(),
//           idx == launchCmdlet.getLaunchActions().size(), action));
//     }
//     Cmdlet cmdlet = new Cmdlet(actions);
//     cmdlet.setId(launchCmdlet.getCmdletId());
//     return cmdlet;
//   }
// 
//   public SmartAction createAction(long cmdletId, boolean isLastAction, LaunchAction launchAction)
//       throws ActionException {
//     SmartAction smartAction = ActionRegistry.createAction(launchAction.getActionType());
//     smartAction.setContext(smartContext);
//     smartAction.setCmdletId(cmdletId);
//     smartAction.setLastAction(isLastAction);
//     smartAction.init(launchAction.getArgs());
//     smartAction.setActionId(launchAction.getActionId());
//     if (smartAction instanceof HdfsAction) {
//       try {
//         ((HdfsAction) smartAction)
//             .setDfsClient(
//                 new SmartDFSClient(
//                     HadoopUtil.getNameNodeUri(smartContext.getConf()),
//                     smartContext.getConf(),
//                     getRpcServerAddress()));
//       } catch (IOException e) {
//         LOG.error("smartAction aid={} setDfsClient error", launchAction.getActionId(), e);
//         throw new ActionException(e);
//       }
//     }
//     /*
//     else if (smartAction instanceof AlluxioAction) {
//       FileSystem fs;
//       try {
//         fs =  AlluxioUtil.getAlluxioFs(smartContext);
//       } catch (Exception e) {
//         LOG.error("smartAction aid={} alluxio filesystem error", launchAction.getActionId(), e);
//         throw new ActionException(e);
//       }
//       ((AlluxioAction) smartAction).setFileSystem(fs);
//     }
//     */
//     return smartAction;
//   }
// 
//   private InetSocketAddress getRpcServerAddress() {
//     String[] strings =
//         smartContext
//             .getConf()
//             .get(
//                 SmartConfKeys.SMART_SERVER_RPC_ADDRESS_KEY,
//                 SmartConfKeys.SMART_SERVER_RPC_ADDRESS_DEFAULT)
//             .split(":");
//     return new InetSocketAddress(
//         strings[strings.length - 2], Integer.parseInt(strings[strings.length - 1]));
//   }
// }
// 
// Path: smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/message/LaunchCmdlet.java
// public class LaunchCmdlet implements AgentService.Message {
//   private long cmdletId;
//   private List<LaunchAction> launchActions;
//   private CmdletDispatchPolicy dispPolicy = CmdletDispatchPolicy.ANY;
//   private String nodeId;
// 
//   public LaunchCmdlet(long cmdletId, List<LaunchAction> launchActions) {
//     this.cmdletId = cmdletId;
//     this.launchActions = launchActions;
//   }
// 
//   public long getCmdletId() {
//     return cmdletId;
//   }
// 
//   public void setCmdletId(long cmdletId) {
//     this.cmdletId = cmdletId;
//   }
// 
//   public List<LaunchAction> getLaunchActions() {
//     return launchActions;
//   }
// 
//   public void setLaunchActions(List<LaunchAction> launchActions) {
//     this.launchActions = launchActions;
//   }
// 
//   @Override
//   public String getServiceName() {
//     return AgentCmdletService.NAME;
//   }
// 
//   public CmdletDispatchPolicy getDispPolicy() {
//     return dispPolicy;
//   }
// 
//   public void setDispPolicy(CmdletDispatchPolicy dispPolicy) {
//     this.dispPolicy = dispPolicy;
//   }
// 
//   @Override
//   public String toString() {
//     return String.format("{cmdletId = %d, dispPolicy = '%s'}", cmdletId, dispPolicy);
//   }
// 
//   public String getNodeId() {
//     return nodeId;
//   }
// 
//   public void setNodeId(String nodeId) {
//     this.nodeId = nodeId;
//   }
// }


import org.smartdata.AgentService;
import org.smartdata.conf.SmartConf;
import org.smartdata.server.engine.cmdlet.CmdletExecutor;
import org.smartdata.server.engine.cmdlet.CmdletFactory;
import org.smartdata.server.engine.cmdlet.message.LaunchCmdlet;
import org.smartdata.server.engine.cmdlet.message.StopCmdlet;
import java.io.IOException;
/**
 * 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.smartdata.server.engine.cmdlet.agent;



public class AgentCmdletService extends AgentService {
  public static final String NAME = "AgentCmdletService";
  private CmdletExecutor executor;
  private CmdletFactory factory;

// Path: smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/CmdletFactory.java
// public class CmdletFactory {
//   static final Logger LOG = LoggerFactory.getLogger(CmdletFactory.class);
//   private final SmartContext smartContext;
//   private final StatusReporter reporter;
// 
//   public CmdletFactory(SmartContext smartContext) {
//     this(smartContext, null);
//   }
// 
//   public CmdletFactory(SmartContext smartContext, StatusReporter reporter) {
//     this.smartContext = smartContext;
//     this.reporter = reporter;
//   }
// 
//   public Cmdlet createCmdlet(LaunchCmdlet launchCmdlet) throws ActionException {
//     List<SmartAction> actions = new ArrayList<>();
//     int idx = 0;
//     for (LaunchAction action : launchCmdlet.getLaunchActions()) {
//       idx++;
//       actions.add(createAction(launchCmdlet.getCmdletId(),
//           idx == launchCmdlet.getLaunchActions().size(), action));
//     }
//     Cmdlet cmdlet = new Cmdlet(actions);
//     cmdlet.setId(launchCmdlet.getCmdletId());
//     return cmdlet;
//   }
// 
//   public SmartAction createAction(long cmdletId, boolean isLastAction, LaunchAction launchAction)
//       throws ActionException {
//     SmartAction smartAction = ActionRegistry.createAction(launchAction.getActionType());
//     smartAction.setContext(smartContext);
//     smartAction.setCmdletId(cmdletId);
//     smartAction.setLastAction(isLastAction);
//     smartAction.init(launchAction.getArgs());
//     smartAction.setActionId(launchAction.getActionId());
//     if (smartAction instanceof HdfsAction) {
//       try {
//         ((HdfsAction) smartAction)
//             .setDfsClient(
//                 new SmartDFSClient(
//                     HadoopUtil.getNameNodeUri(smartContext.getConf()),
//                     smartContext.getConf(),
//                     getRpcServerAddress()));
//       } catch (IOException e) {
//         LOG.error("smartAction aid={} setDfsClient error", launchAction.getActionId(), e);
//         throw new ActionException(e);
//       }
//     }
//     /*
//     else if (smartAction instanceof AlluxioAction) {
//       FileSystem fs;
//       try {
//         fs =  AlluxioUtil.getAlluxioFs(smartContext);
//       } catch (Exception e) {
//         LOG.error("smartAction aid={} alluxio filesystem error", launchAction.getActionId(), e);
//         throw new ActionException(e);
//       }
//       ((AlluxioAction) smartAction).setFileSystem(fs);
//     }
//     */
//     return smartAction;
//   }
// 
//   private InetSocketAddress getRpcServerAddress() {
//     String[] strings =
//         smartContext
//             .getConf()
//             .get(
//                 SmartConfKeys.SMART_SERVER_RPC_ADDRESS_KEY,
//                 SmartConfKeys.SMART_SERVER_RPC_ADDRESS_DEFAULT)
//             .split(":");
//     return new InetSocketAddress(
//         strings[strings.length - 2], Integer.parseInt(strings[strings.length - 1]));
//   }
// }
// 
// Path: smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/message/LaunchCmdlet.java
// public class LaunchCmdlet implements AgentService.Message {
//   private long cmdletId;
//   private List<LaunchAction> launchActions;
//   private CmdletDispatchPolicy dispPolicy = CmdletDispatchPolicy.ANY;
//   private String nodeId;
// 
//   public LaunchCmdlet(long cmdletId, List<LaunchAction> launchActions) {
//     this.cmdletId = cmdletId;
//     this.launchActions = launchActions;
//   }
// 
//   public long getCmdletId() {
//     return cmdletId;
//   }
// 
//   public void setCmdletId(long cmdletId) {
//     this.cmdletId = cmdletId;
//   }
// 
//   public List<LaunchAction> getLaunchActions() {
//     return launchActions;
//   }
// 
//   public void setLaunchActions(List<LaunchAction> launchActions) {
//     this.launchActions = launchActions;
//   }
// 
//   @Override
//   public String getServiceName() {
//     return AgentCmdletService.NAME;
//   }
// 
//   public CmdletDispatchPolicy getDispPolicy() {
//     return dispPolicy;
//   }
// 
//   public void setDispPolicy(CmdletDispatchPolicy dispPolicy) {
//     this.dispPolicy = dispPolicy;
//   }
// 
//   @Override
//   public String toString() {
//     return String.format("{cmdletId = %d, dispPolicy = '%s'}", cmdletId, dispPolicy);
//   }
// 
//   public String getNodeId() {
//     return nodeId;
//   }
// 
//   public void setNodeId(String nodeId) {
//     this.nodeId = nodeId;
//   }
// }


// Path: smart-engine/src/main/java/org/smartdata/server/engine/cmdlet/agent/AgentCmdletService.java
import org.smartdata.AgentService;
import org.smartdata.conf.SmartConf;
import org.smartdata.server.engine.cmdlet.CmdletExecutor;
import org.smartdata.server.engine.cmdlet.CmdletFactory;
import org.smartdata.server.engine.cmdlet.message.LaunchCmdlet;
import org.smartdata.server.engine.cmdlet.message.StopCmdlet;
import java.io.IOException;

/**
 * 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.smartdata.server.engine.cmdlet.agent;



public class AgentCmdletService extends AgentService {
  public static final String NAME = "AgentCmdletService";
  private CmdletExecutor executor;
  private CmdletFactory factory;

  public AgentCmdletService() {