Ejemplo n.º 1
0
  public StatusBean delete(JsonNode projectData) {
    StatusBean statusBean = new StatusBean();
    Integer userID = Integer.parseInt(projectData.get("userID").getTextValue());
    Integer projectID = Integer.parseInt(projectData.get("projectID").getTextValue());
    String location = Utilities.getInstance().fetchActiveProjectDirectory(userID);

    try {
      ProjectBean project = projectDao.queryForId(projectID);
      project.setIsDisabled(true);
      projectDao.update(project);
      List<MachineConfigurationBean> machineConfigList =
          MachineConfigDAOManager.getInstance().retireveBoxesForProject(projectID.toString());

      for (MachineConfigurationBean machineConfig : machineConfigList) {
        MachineConfigDAOManager.getInstance().delete(machineConfig.getMachineID().toString());
        String vagrantCommand = "vagrant destroy " + machineConfig.getVagrantID();
        VagrantCommandProcessor shellProcessor = new VagrantCommandProcessor();
        try {
          shellProcessor.executeVagrantFile(
              location, vagrantCommand, userID, new VagrantOutputStream());
        } catch (IOException e) {
          statusBean.setStatusCode(1);
          statusBean.setStatusMessage("error in destroting box" + e.getMessage());
        } catch (InterruptedException e) {
          statusBean.setStatusCode(1);
          statusBean.setStatusMessage("error in destroting box" + e.getMessage());
        }
      }

    } catch (SQLException e) {
      logger.error("Error deleting a project : " + e.getMessage());
      statusBean.setStatusCode(1);
      statusBean.setStatusMessage("Error deleting  a project : " + e.getMessage());
      e.printStackTrace();
    }
    statusBean.setStatusCode(0);
    statusBean.setStatusMessage("Project deleted successfully");
    return statusBean;
  }
Ejemplo n.º 2
0
  @Override
  public StatusBean create(JsonNode newData) {
    ProjectBean projectBean = new ProjectBean();
    Gson projectData = new GsonBuilder().setDateFormat("yyyy'-'MM'-'dd HH':'mm':'ss").create();
    projectBean = projectData.fromJson(newData.toString(), ProjectBean.class);

    StatusBean statusBean = new StatusBean();

    try {

      int rowsUpdated = projectDao.create(projectBean);

      // if(rowsUpdated == 1)
      // Utilities.getInstance().changeActiveDirectory(projectBean.getProjectId());
      UserDAOManager.getInstance()
          .populateMappingBean(projectBean, newData.get("owner").getValueAsText());
      statusBean.setStatusCode(0);
      statusBean.setData(projectBean);
      Utilities.getInstance().initializeDirectory(projectBean.getProjectID());
      String scriptDir =
          Utilities.getInstance().constructProjectDirectory(projectBean.getProjectID())
              + OSProperties.getInstance().getOSFileSeparator()
              + OSProperties.getInstance().getScriptsDirName()
              + OSProperties.getInstance().getOSFileSeparator();
      Utilities.getInstance().checkIfDirExists(new File(scriptDir));
      //			File puppetScriptFile = new File(getClass().getResource("/puppet.sh").toURI());
      InputStream puppetScriptStream = getClass().getResourceAsStream("/puppet.sh");
      File puppetFile = new File("puppet.sh");
      OutputStream outputStream = new FileOutputStream(puppetFile);
      IOUtils.copy(puppetScriptStream, outputStream);

      Utilities.getInstance().copyFile(puppetFile, new File(scriptDir + "puppet.sh"));

      String nodeFileLoc =
          Utilities.getInstance().constructProjectDirectory(projectBean.getProjectID())
              + OSProperties.getInstance().getOSFileSeparator()
              + OSProperties.getInstance().getManifestsDirName()
              + OSProperties.getInstance().getOSFileSeparator()
              + "site.pp";
      boolean nodeFile = new File(nodeFileLoc).createNewFile();

      Integer providerID =
          ProviderDAOManager.getInstance()
              .providerDao
              .queryForId(projectBean.getProviderType())
              .getProviderID();
      ProjectProviderMappingBean projectProvider =
          new ProjectProviderMappingBean(projectBean.getProjectID(), providerID);
      projectProviderMappingDao.create(projectProvider);
      String providerName =
          ProviderDAOManager.getInstance()
              .providerDao
              .queryForId(projectBean.getProviderType())
              .getName();
      if (providerName.equalsIgnoreCase(CommonProperties.getInstance().getDockerProvider())) {
        Utilities.getInstance().initializeDockerVagrantFile(projectBean.getProjectID());
      } else if (providerName.equalsIgnoreCase(AwsProjectDAOManager.PROVIDER_NAME)) {
        AwsProjectDAOManager.getInstance().create(newData, projectBean);
      }
    } catch (SQLException e) {
      logger.error("Error creating a new project : " + e.getMessage());
      statusBean.setStatusCode(1);
      statusBean.setStatusMessage("Error creating project : " + e.getMessage());

    } catch (IOException e) {
      e.printStackTrace();
    }
    return statusBean;
  }