agave-apps/apps-core/src/main/java/org/iplantc/service/apps/queue/actions/PublishAction.java
/**
     * Backs up an app's assets to the platform cloud storage in a folder 
     * named after the tenant.
     */
Backs up an app's assets to the platform cloud storage in a folder
named after the tenant.
Backs up an app ' s assets to the platform cloud storage in a folder named after the tenant .
public void schedulePublicAppAssetBundleBackup() 
    {
        String srcUrl = "";
        String destUrl = "";
        try 
        {
            SystemDao dao = new SystemDao();
            RemoteSystem platformArchiveSystem = new SystemManager().getPlatformStorageSystem();
            RemoteDataClient platformArchiveSystemDataClient = platformArchiveSystem.getRemoteDataClient();
            StorageSystem appStorageSystem = publishedSoftware.getStorageSystem();
            srcUrl = "agave://" + appStorageSystem.getSystemId() + "/" + publishedSoftware.getDeploymentPath();
            destUrl = "agave://" + org.iplantc.service.common.Settings.PLATFORM_STORAGE_SYSTEM_ID + "/" + publishedSoftware.getTenantId() + "/" + publishedSoftware.getDeploymentPath();
            if (StringUtils.isEmpty(org.iplantc.service.common.Settings.PLATFORM_STORAGE_SYSTEM_ID)) 
            {
                throw new SystemUnknownException("While attempting to backup the public app bundle for " + publishedSoftware.getUniqueName() + 
                        " the platform storage system was not defined for the current tenant. You may " + 
                        " manually back up the public app bundle by defining a platform backup storage system " + 
                        " and copying it from " + srcUrl +
                        " to  " + publishedSoftware.getTenantId() + "/" + publishedSoftware.getDeploymentPath() + " on the new sytem.");
            } 
            else 
            {
                RemoteSystem system = dao.findBySystemId(org.iplantc.service.common.Settings.PLATFORM_STORAGE_SYSTEM_ID);
                if (system == null) 
                {
                    throw new SystemUnknownException("While attempting to backup the public app bundle for " + publishedSoftware.getUniqueName() + 
                                " the platform storage system " + org.iplantc.service.common.Settings.PLATFORM_STORAGE_SYSTEM_ID + 
                                ", an error occurred preventing the backup from succeeding. You may " + 
                                " manually back up the public app bundle by copying it from " + srcUrl +
                                " to " + destUrl);
                } 
                else
                {
                    LogicalFile logicalFile = new LogicalFile();
                    logicalFile.setStatus(StagingTaskStatus.STAGING_QUEUED);
                    logicalFile.setOwner("xxx");
                    logicalFile.setInternalUsername(null);
                    logicalFile.setSourceUri(srcUrl);
                    logicalFile.setNativeFormat("RAW");
                    logicalFile.setSystem(platformArchiveSystem);
                    logicalFile.setName(FilenameUtils.getName(publishedSoftware.getDeploymentPath()));
                    logicalFile.setPath(platformArchiveSystemDataClient.resolvePath("/" + publishedSoftware.getTenantId() + "/" + publishedSoftware.getDeploymentPath()));
                    LogicalFileDao.persist(logicalFile);
                    logicalFile.addContentEvent(new FileEvent(logicalFile,
                                    FileEventType.STAGING_QUEUED,
                                    "Public app archive queued for cloud backup.",
                                    publishedSoftware.getOwner()));
                    LogicalFileDao.persist(logicalFile);
                    QueueTaskDao.enqueueStagingTask(logicalFile, getPublishingUsername());
                    LogicalFileDao.updateTransferStatus(logicalFile, StagingTaskStatus.STAGING_QUEUED, "xxx");
                }
            }
        }
        catch (SystemUnknownException e) {
            try {
                Tenant tenant = new TenantDao().findByTenantId(TenancyHelper.getCurrentTenantId());
                EmailMessage.send(tenant.getContactName(), 
                        tenant.getContactEmail(), 
                        "Failed to back up app bundle for " + publishedSoftware.getUniqueName(),
                        e.getMessage(), HTMLizer.htmlize(e.getMessage()));
            }
            catch (Throwable t) {
                log.error("Failed to notify admin that backup of " + publishedSoftware.getUniqueName() + " app bundle failed.", t);
            }
            throw new SoftwareException("Failed to backup the public app bundle from " + 
                    srcUrl + " to " + destUrl);
        }
        catch (Throwable e) 
        {
            try {
                Tenant tenant = new TenantDao().findByTenantId(TenancyHelper.getCurrentTenantId());
                String message =  
                        "While attempting to backup the public app bundle for " + publishedSoftware.getUniqueName() + 
                        " to the platform storage system " + org.iplantc.service.common.Settings.PLATFORM_STORAGE_SYSTEM_ID + 
                        ", an error occurred preventing the backup from succeeding. You may " + 
                        " manually back up the public app bundle by copying it from " + srcUrl +
                        " to " + destUrl;
                EmailMessage.send(tenant.getContactName(), 
                        tenant.getContactEmail(), 
                        "Failed to back up app bundle for " + publishedSoftware.getUniqueName(),
                        message, HTMLizer.htmlize(message));
            }
            catch (Throwable t) {
                log.error("Failed to notify admin that backup of " + publishedSoftware.getUniqueName() + " app bundle failed.", t);
            }
            throw new SoftwareException("Failed to backup the public app bundle from " + 
                    srcUrl + " to " + destUrl);
        }
    }
public void schedulePublicAppAssetBundleBackup ( ) { String srcUrl = "" ; String destUrl = "" ; try { SystemDao dao = new SystemDao ( ) ; RemoteSystem platformArchiveSystem = new SystemManager ( ) . getPlatformStorageSystem ( ) ; RemoteDataClient platformArchiveSystemDataClient = platformArchiveSystem . getRemoteDataClient ( ) ; StorageSystem appStorageSystem = publishedSoftware . getStorageSystem ( ) ; srcUrl = "agave://" + appStorageSystem . getSystemId ( ) + "/" + publishedSoftware . getDeploymentPath ( ) ; destUrl = "agave://" + org . iplantc . service . common . Settings . PLATFORM_STORAGE_SYSTEM_ID + "/" + publishedSoftware . getTenantId ( ) + "/" + publishedSoftware . getDeploymentPath ( ) ; if ( StringUtils . isEmpty ( org . iplantc . service . common . Settings . PLATFORM_STORAGE_SYSTEM_ID ) ) { throw new SystemUnknownException ( "While attempting to backup the public app bundle for " + publishedSoftware . getUniqueName ( ) + " the platform storage system was not defined for the current tenant. You may " + " manually back up the public app bundle by defining a platform backup storage system " + " and copying it from " + srcUrl + " to  " + publishedSoftware . getTenantId ( ) + "/" + publishedSoftware . getDeploymentPath ( ) + " on the new sytem." ) ; } else { RemoteSystem system = dao . findBySystemId ( org . iplantc . service . common . Settings . PLATFORM_STORAGE_SYSTEM_ID ) ; if ( system == null ) { throw new SystemUnknownException ( "While attempting to backup the public app bundle for " + publishedSoftware . getUniqueName ( ) + " the platform storage system " + org . iplantc . service . common . Settings . PLATFORM_STORAGE_SYSTEM_ID + ", an error occurred preventing the backup from succeeding. You may " + " manually back up the public app bundle by copying it from " + srcUrl + " to " + destUrl ) ; } else { LogicalFile logicalFile = new LogicalFile ( ) ; logicalFile . setStatus ( StagingTaskStatus . STAGING_QUEUED ) ; logicalFile . setOwner ( "xxx" ) ; logicalFile . setInternalUsername ( null ) ; logicalFile . setSourceUri ( srcUrl ) ; logicalFile . setNativeFormat ( "RAW" ) ; logicalFile . setSystem ( platformArchiveSystem ) ; logicalFile . setName ( FilenameUtils . getName ( publishedSoftware . getDeploymentPath ( ) ) ) ; logicalFile . setPath ( platformArchiveSystemDataClient . resolvePath ( "/" + publishedSoftware . getTenantId ( ) + "/" + publishedSoftware . getDeploymentPath ( ) ) ) ; LogicalFileDao . persist ( logicalFile ) ; logicalFile . addContentEvent ( new FileEvent ( logicalFile , FileEventType . STAGING_QUEUED , "Public app archive queued for cloud backup." , publishedSoftware . getOwner ( ) ) ) ; LogicalFileDao . persist ( logicalFile ) ; QueueTaskDao . enqueueStagingTask ( logicalFile , getPublishingUsername ( ) ) ; LogicalFileDao . updateTransferStatus ( logicalFile , StagingTaskStatus . STAGING_QUEUED , "xxx" ) ; } } } catch ( SystemUnknownException e ) { try { Tenant tenant = new TenantDao ( ) . findByTenantId ( TenancyHelper . getCurrentTenantId ( ) ) ; EmailMessage . send ( tenant . getContactName ( ) , tenant . getContactEmail ( ) , "Failed to back up app bundle for " + publishedSoftware . getUniqueName ( ) , e . getMessage ( ) , HTMLizer . htmlize ( e . getMessage ( ) ) ) ; } catch ( Throwable t ) { log . error ( "Failed to notify admin that backup of " + publishedSoftware . getUniqueName ( ) + " app bundle failed." , t ) ; } throw new SoftwareException ( "Failed to backup the public app bundle from " + srcUrl + " to " + destUrl ) ; } catch ( Throwable e ) { try { Tenant tenant = new TenantDao ( ) . findByTenantId ( TenancyHelper . getCurrentTenantId ( ) ) ; String message = "While attempting to backup the public app bundle for " + publishedSoftware . getUniqueName ( ) + " to the platform storage system " + org . iplantc . service . common . Settings . PLATFORM_STORAGE_SYSTEM_ID + ", an error occurred preventing the backup from succeeding. You may " + " manually back up the public app bundle by copying it from " + srcUrl + " to " + destUrl ; EmailMessage . send ( tenant . getContactName ( ) , tenant . getContactEmail ( ) , "Failed to back up app bundle for " + publishedSoftware . getUniqueName ( ) , message , HTMLizer . htmlize ( message ) ) ; } catch ( Throwable t ) { log . error ( "Failed to notify admin that backup of " + publishedSoftware . getUniqueName ( ) + " app bundle failed." , t ) ; } throw new SoftwareException ( "Failed to backup the public app bundle from " + srcUrl + " to " + destUrl ) ; } }
Backs up an app's assets to the platform cloud storage in a folder
 named after the tenant.
Backs up an app ' s assets to the platform cloud storage in a folder named after the tenant .
// add the logical file to the staging queue