예제 #1
0
  public void run(List<JsonNode> steps) {
    Map<String, Object> globalConfig = flotoService.createGlobalConfig(manifest);
    HostManipulator hostManipulator = new HypervisorHostManipulator(hypervisorService, vmName);
    for (JsonNode step : steps) {
      String stepType = step.get("type").asText();
      switch (stepType) {
        case "ADD_TEMPLATE":
          String destination = step.path("destination").asText();
          String templated = new TemplateUtil().getTemplate(step, globalConfig);
          hostManipulator.writeToVm(templated, destination);
          break;
        case "RUN":
          String line = step.path("line").asText();
          if (flotoService.isUseProxy()) {
            line = "http_proxy='" + flotoService.getHttpProxyUrl() + "' " + line;
          }
          hostManipulator.run(line);
          break;
        case "DETERMINE_IP":
          String command = step.path("command").asText();
          File ipFile = null;
          try {
            ipFile = File.createTempFile("floto-", "-guestFile");
            hypervisorService.runInVm(vmName, command + " > /ip.txt");
            hypervisorService.runInVm(vmName, "chmod 755 /ip.txt");
            hypervisorService.copyFileFromGuest(vmName, "/ip.txt", ipFile);
            String ipAddress = FileUtils.readFileToString(ipFile).replaceAll("\\s", "");
            if (ipAddress.isEmpty()) {
              ipAddress = host.ip;
            }
            log.info("Using IP {} for host {}", ipAddress, vmName);
            flotoService.setExternalHostIp(host.name, ipAddress);
            hostManipulator = new SshHostManipulator(ipAddress);
            hypervisorService.runInVm(vmName, "rm /ip.txt");
          } catch (IOException e) {
            throw Throwables.propagate(e);
          } finally {
            FileUtils.deleteQuietly(ipFile);
          }
          break;
        case "SET_HOST_ONLY_IP":
          String osName = System.getProperty("os.name");
          if (osName.indexOf("Windows") != -1) {
            String proxy = "http_proxy='" + flotoService.getHttpProxyUrl() + "' ";
            hypervisorService.setHostOnlyIpVBoxWin(vmName, proxy);
          } else {
            log.info("This method is only for Windowsusers with virtualbox. Please use DHCP");
          }

          break;
        default:
          throw new IllegalArgumentException("No handler for step type " + step + "\n" + step);
      }
    }
  }
예제 #2
0
 @POST
 @Path("_destroyUnmanaged")
 @Produces(MediaType.APPLICATION_JSON)
 public TaskInfo<Void> destroyUnmanagedContainer(UnmanagedContainerRequest containerRequest) {
   return flotoService.destroyUnmanagedContainer(
       containerRequest.containerName, containerRequest.hostName);
 }
예제 #3
0
 @POST
 @Path("_redeploy")
 @Produces(MediaType.APPLICATION_JSON)
 public TaskInfo<Void> redeployContainers(ContainersRequest containersRequest) {
   return flotoService.redeployContainers(
       containersRequest.containers, containersRequest.deploymentMode);
 }
예제 #4
0
 @GET
 @Path("_state")
 @Produces(MediaType.APPLICATION_JSON)
 public Map<String, Object> getState() {
   Map<String, Object> result = new HashMap<>();
   result.put("states", flotoService.getContainerStates());
   return result;
 }
예제 #5
0
 @POST
 @Path("_purgeData")
 @Produces(MediaType.APPLICATION_JSON)
 public TaskInfo<Void> purgeData(ContainersRequest containersRequest) {
   return flotoService.purgeContainerData(containersRequest.containers);
 }
예제 #6
0
 @POST
 @Path("_restart")
 @Produces(MediaType.APPLICATION_JSON)
 public TaskInfo<Void> restartContainers(ContainersRequest containersRequest) {
   return flotoService.restartContainers(containersRequest.containers);
 }