Package com.dotcms.publisher.business

Examples of com.dotcms.publisher.business.PublishAuditHistory


    public PublisherConfig process ( final PublishStatus status ) throws DotPublishingException {
    if(LicenseUtil.getLevel()<300) {
          throw new RuntimeException("need an enterprise pro license to run this bundler");
        }

      PublishAuditHistory currentStatusHistory = null;
    try {
      //Compressing bundle
      File bundleRoot = BundlerUtil.getBundleRoot(config);

      ArrayList<File> list = new ArrayList<File>(1);
      list.add(bundleRoot);
      File bundle = new File(bundleRoot+File.separator+".."+File.separator+config.getId()+".tar.gz");
      PushUtils.compressFiles(list, bundle, bundleRoot.getAbsolutePath());

      List<Environment> environments = APILocator.getEnvironmentAPI().findEnvironmentsByBundleId(config.getId());

      ClientConfig cc = new DefaultClientConfig();

      if(Config.getStringProperty("TRUSTSTORE_PATH") != null && !Config.getStringProperty("TRUSTSTORE_PATH").trim().equals("")) {
        cc.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(tFactory.getHostnameVerifier(), tFactory.getSSLContext()));
            }
      Client client = Client.create(cc);

      //Updating audit table
      currentStatusHistory = pubAuditAPI.getPublishAuditStatus(config.getId()).getStatusPojo();

      currentStatusHistory.setPublishStart(new Date());
      pubAuditAPI.updatePublishAuditStatus(config.getId(), PublishAuditStatus.Status.SENDING_TO_ENDPOINTS, currentStatusHistory);
      //Increment numTries
      currentStatusHistory.addNumTries();


//          boolean hasError = false;
          int errorCounter = 0;

      for (Environment environment : environments) {
        List<PublishingEndPoint> endpoints = APILocator.getPublisherEndPointAPI().findSendingEndPointsByEnvironment(environment.getId());

        boolean failedEnvironment = false;

        if(!environment.getPushToAll()) {
          Collections.shuffle(endpoints);
          if(!endpoints.isEmpty())
            endpoints = endpoints.subList(0, 1);
        }

        for (PublishingEndPoint endpoint : endpoints) {
          EndpointDetail detail = new EndpointDetail();
              try {
                FormDataMultiPart form = new FormDataMultiPart();
                form.field("AUTH_TOKEN",
                    retriveKeyString(
                        PublicEncryptionFactory.decryptString(endpoint.getAuthKey().toString())));

                form.field("GROUP_ID", UtilMethods.isSet(endpoint.getGroupId()) ? endpoint.getGroupId() : endpoint.getId());
                Bundle b=APILocator.getBundleAPI().getBundleById(config.getId());
                form.field("BUNDLE_NAME", b.getName());
                form.field("ENDPOINT_ID", endpoint.getId());
                form.bodyPart(new FileDataBodyPart("bundle", bundle, MediaType.MULTIPART_FORM_DATA_TYPE));


                //Sending bundle to endpoint
                WebResource resource = client.resource(endpoint.toURL()+"/api/bundlePublisher/publish");

                ClientResponse response =
                    resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);


                if(response.getClientResponseStatus().getStatusCode() == HttpStatus.SC_OK)
                {
                  detail.setStatus(PublishAuditStatus.Status.BUNDLE_SENT_SUCCESSFULLY.getCode());
                  detail.setInfo("Everything ok");
                } else {

                  if(currentStatusHistory.getNumTries()==PublisherQueueJob.MAX_NUM_TRIES) {
                    APILocator.getPushedAssetsAPI().deletePushedAssets(config.getId(), environment.getId());
                  }
                  detail.setStatus(PublishAuditStatus.Status.FAILED_TO_SENT.getCode());
                  detail.setInfo(
                      "Returned "+response.getClientResponseStatus().getStatusCode()+ " status code " +
                          "for the endpoint "+endpoint.getId()+ "with address "+endpoint.getAddress());
                  failedEnvironment |= true;

                }
              } catch(Exception e) {

                // if the bundle can't be sent after the total num of tries, delete the pushed assets for this bundle
                if(currentStatusHistory.getNumTries()==PublisherQueueJob.MAX_NUM_TRIES) {
                  APILocator.getPushedAssetsAPI().deletePushedAssets(config.getId(), environment.getId());
                }
//                hasError = true;
                detail.setStatus(PublishAuditStatus.Status.FAILED_TO_SENT.getCode());

                String error =   "An error occured for the endpoint "+ endpoint.getId() + " with address "+ endpoint.getAddress() + ".  Error: " + e.getMessage();


                detail.setInfo(error);
                failedEnvironment |= true;

                Logger.error(this.getClass(), error);
              }

              currentStatusHistory.addOrUpdateEndpoint(environment.getId(), endpoint.getId(), detail);
        }

        if(failedEnvironment) {
//          hasError = true;
          errorCounter++;
        }


      }

      if(errorCounter==0) {
        //Updating audit table
            currentStatusHistory.setPublishEnd(new Date());
        pubAuditAPI.updatePublishAuditStatus(config.getId(),
            PublishAuditStatus.Status.BUNDLE_SENT_SUCCESSFULLY, currentStatusHistory);

        //Deleting queue records
        //pubAPI.deleteElementsFromPublishQueueTable(config.getId());
View Full Code Here

TOP

Related Classes of com.dotcms.publisher.business.PublishAuditHistory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.