// Path: agent/src/main/java/org/apache/hms/agent/dispatcher/PackageRunner.java
// public class PackageRunner {
//   private static Log log = LogFactory.getLog(PackageRunner.class);
// 
//   public Response install(PackageCommand dc) {
//     dc.setCmd("install");
//     if(dc.getDryRun()) {
//       return dryRun(dc);
//     }
//     return helper(dc);
//   }
//   
//   public Response remove(PackageCommand dc) {
//     dc.setCmd("erase");
//     return helper(dc);
//   }
//   
//   public Response query(PackageCommand dc) {
//     dc.setCmd("info");
//     return helper(dc);
//   }
//   
//   private Response helper(PackageCommand dc) {
//     ScriptCommand cmd = new ScriptCommand();
//     cmd.setCmd(dc.getCmd());
//     Response r = null;
//     cmd.setScript("yum");
//     String[] parms = null;
//     if(dc.getPackages().length>0) {
//       parms = new String[dc.getPackages().length+2];
//       for(int i = 0; i< dc.getPackages().length;i++) {
//         parms[i+2] = dc.getPackages()[i].getName();
//       }
//     }
//     if(parms != null) {
//       parms[0] = dc.getCmd();
//       parms[1] = "-y";
//       cmd.setParms(parms);
//       ShellRunner shell = new ShellRunner();
//       r = shell.run(cmd);
//     } else {
//       r = new Response();
//       r.setCode(1);
//       r.setError("Invalid package name");
//     }
//     return r;    
//   }
//   
//   private Response dryRun(PackageCommand dc) {
//     Response r = null;
//     ScriptCommand cmd = new ScriptCommand();
//     cmd.setCmd(dc.getCmd());
//     cmd.setScript("yum");
//     PackageInfo[] packages = dc.getPackages();
//     String[] parms = new String[packages.length+4];
//     parms[0] = "install";
//     parms[1] = "-y";
//     parms[2] = "--downloadonly";
//     parms[3] = "--downloaddir=/tmp/system_update";
//     for(int i=0;i<packages.length;i++) {
//       parms[i+4] = packages[i].getName();
//     }
//     cmd.setParms(parms);
//     ShellRunner shell = new ShellRunner();
//     r = shell.run(cmd);
//     if(r.getCode()!=1) {
//       return r;
//     } else {
//       cmd.setScript("rpm");
//       String[] rpmParms = new String[3];
//       rpmParms[0] = "-i";
//       rpmParms[1] = "--test";
//       rpmParms[2] = "/tmp/system_update/*.rpm";
//       cmd.setParms(rpmParms);
//       r = shell.run(cmd);
//       FileUtil.deleteDir(new File("/tmp/system_update"));
//       return r;
//     }
//   }
// }
// 
// Path: common/src/main/java/org/apache/hms/common/entity/RestSource.java
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD) 
// @XmlType(name="", propOrder = {})
// public abstract class RestSource {
// 
// }


import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.apache.hms.agent.dispatcher.PackageRunner;
import org.apache.hms.common.entity.PackageCommand;
import org.apache.hms.common.entity.RestSource;
import org.apache.hms.common.rest.Response;
/*
 * 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.hms.agent.rest;



@Path("package")
public class PackageManager extends RestSource {
  
  @POST
  @Path("install")
  public Response install(PackageCommand pc) {
// Path: agent/src/main/java/org/apache/hms/agent/dispatcher/PackageRunner.java
// public class PackageRunner {
//   private static Log log = LogFactory.getLog(PackageRunner.class);
// 
//   public Response install(PackageCommand dc) {
//     dc.setCmd("install");
//     if(dc.getDryRun()) {
//       return dryRun(dc);
//     }
//     return helper(dc);
//   }
//   
//   public Response remove(PackageCommand dc) {
//     dc.setCmd("erase");
//     return helper(dc);
//   }
//   
//   public Response query(PackageCommand dc) {
//     dc.setCmd("info");
//     return helper(dc);
//   }
//   
//   private Response helper(PackageCommand dc) {
//     ScriptCommand cmd = new ScriptCommand();
//     cmd.setCmd(dc.getCmd());
//     Response r = null;
//     cmd.setScript("yum");
//     String[] parms = null;
//     if(dc.getPackages().length>0) {
//       parms = new String[dc.getPackages().length+2];
//       for(int i = 0; i< dc.getPackages().length;i++) {
//         parms[i+2] = dc.getPackages()[i].getName();
//       }
//     }
//     if(parms != null) {
//       parms[0] = dc.getCmd();
//       parms[1] = "-y";
//       cmd.setParms(parms);
//       ShellRunner shell = new ShellRunner();
//       r = shell.run(cmd);
//     } else {
//       r = new Response();
//       r.setCode(1);
//       r.setError("Invalid package name");
//     }
//     return r;    
//   }
//   
//   private Response dryRun(PackageCommand dc) {
//     Response r = null;
//     ScriptCommand cmd = new ScriptCommand();
//     cmd.setCmd(dc.getCmd());
//     cmd.setScript("yum");
//     PackageInfo[] packages = dc.getPackages();
//     String[] parms = new String[packages.length+4];
//     parms[0] = "install";
//     parms[1] = "-y";
//     parms[2] = "--downloadonly";
//     parms[3] = "--downloaddir=/tmp/system_update";
//     for(int i=0;i<packages.length;i++) {
//       parms[i+4] = packages[i].getName();
//     }
//     cmd.setParms(parms);
//     ShellRunner shell = new ShellRunner();
//     r = shell.run(cmd);
//     if(r.getCode()!=1) {
//       return r;
//     } else {
//       cmd.setScript("rpm");
//       String[] rpmParms = new String[3];
//       rpmParms[0] = "-i";
//       rpmParms[1] = "--test";
//       rpmParms[2] = "/tmp/system_update/*.rpm";
//       cmd.setParms(rpmParms);
//       r = shell.run(cmd);
//       FileUtil.deleteDir(new File("/tmp/system_update"));
//       return r;
//     }
//   }
// }
// 
// Path: common/src/main/java/org/apache/hms/common/entity/RestSource.java
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD) 
// @XmlType(name="", propOrder = {})
// public abstract class RestSource {
// 
// }


// Path: agent/src/main/java/org/apache/hms/agent/rest/PackageManager.java
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.apache.hms.agent.dispatcher.PackageRunner;
import org.apache.hms.common.entity.PackageCommand;
import org.apache.hms.common.entity.RestSource;
import org.apache.hms.common.rest.Response;

/*
 * 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.hms.agent.rest;



@Path("package")
public class PackageManager extends RestSource {
  
  @POST
  @Path("install")
  public Response install(PackageCommand pc) {
    PackageRunner pr = new PackageRunner();