|
|
@ -19,8 +19,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.impl;
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Application;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Application;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ImageArtifact;
|
|
|
@ -28,7 +31,9 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil;
|
|
|
|
|
|
|
|
|
|
|
@ -62,109 +67,93 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void uploadImageArtifacts(String applicationUUID, InputStream iconFileStream, InputStream bannerFileStream,
|
|
|
|
public ApplicationRelease uploadImageArtifacts(int applicationId, ApplicationRelease applicationRelease,
|
|
|
|
List<InputStream> screenShotStreams) throws ResourceManagementException {
|
|
|
|
InputStream iconFileStream, InputStream bannerFileStream, List<InputStream> screenShotStreams) throws ResourceManagementException {
|
|
|
|
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
// Application application = validateApplication(applicationUUID);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
// String artifactDirectoryPath = storagePath + application.getId();
|
|
|
|
String artifactDirectoryPath = null;
|
|
|
|
// if (log.isDebugEnabled()) {
|
|
|
|
String iconStoredLocation;
|
|
|
|
// log.debug("Artifact Directory Path for saving the artifacts related with application " + applicationUUID
|
|
|
|
String bannerStoredLocation;
|
|
|
|
// + " is " + artifactDirectoryPath);
|
|
|
|
String scStoredLocation;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
|
|
|
|
try {
|
|
|
|
// if (iconFileStream != null) {
|
|
|
|
if (validateApplication(applicationId)) {
|
|
|
|
// try {
|
|
|
|
artifactDirectoryPath = storagePath + applicationRelease.getAppHashValue();
|
|
|
|
// saveFile(iconFileStream, artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[0]);
|
|
|
|
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
|
|
|
|
// } catch (IOException e) {
|
|
|
|
}
|
|
|
|
// throw new ApplicationStorageManagementException(
|
|
|
|
|
|
|
|
// "IO Exception while saving the icon file in the server for " + "the application "
|
|
|
|
if (artifactDirectoryPath != null) {
|
|
|
|
// + applicationUUID, e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
iconStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[0];
|
|
|
|
// }
|
|
|
|
bannerStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[1];
|
|
|
|
// if (bannerFileStream != null) {
|
|
|
|
saveFile(iconFileStream, iconStoredLocation);
|
|
|
|
// try {
|
|
|
|
saveFile(bannerFileStream, bannerStoredLocation);
|
|
|
|
// saveFile(bannerFileStream, artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[1]);
|
|
|
|
applicationRelease.setIconLoc(iconStoredLocation);
|
|
|
|
// } catch (IOException e) {
|
|
|
|
applicationRelease.setBannerLoc(bannerStoredLocation);
|
|
|
|
// throw new ApplicationStorageManagementException(
|
|
|
|
|
|
|
|
// "IO Exception while saving the banner file in the server for" + " the application "
|
|
|
|
if (screenShotStreams.size() > screenShotMaxCount) {
|
|
|
|
// + applicationUUID, e);
|
|
|
|
throw new ApplicationStorageManagementException("Maximum limit for the screen-shot exceeds");
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (screenShotStreams != null) {
|
|
|
|
int count = 1;
|
|
|
|
// int count = application.getScreenShotCount() + 1;
|
|
|
|
for (InputStream screenshotStream : screenShotStreams) {
|
|
|
|
// boolean maxCountReached = false;
|
|
|
|
scStoredLocation = artifactDirectoryPath + File.separator + Constants.IMAGE_ARTIFACTS[2] + count;
|
|
|
|
//
|
|
|
|
if (count == 1) {
|
|
|
|
// if (count > screenShotMaxCount) {
|
|
|
|
applicationRelease.setScreenshotLoc1(scStoredLocation);
|
|
|
|
// log.error("Maximum limit for the screen-shot is " + screenShotMaxCount
|
|
|
|
}
|
|
|
|
// + " Cannot upload another screenshot for the application with the UUID " + applicationUUID);
|
|
|
|
if (count == 2) {
|
|
|
|
// maxCountReached = true;
|
|
|
|
applicationRelease.setScreenshotLoc2(scStoredLocation);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// String screenshotName;
|
|
|
|
if (count == 3) {
|
|
|
|
//
|
|
|
|
applicationRelease.setScreenshotLoc3(scStoredLocation);
|
|
|
|
// if (maxCountReached) {
|
|
|
|
}
|
|
|
|
// return;
|
|
|
|
saveFile(screenshotStream, scStoredLocation);
|
|
|
|
// }
|
|
|
|
count++;
|
|
|
|
// for (InputStream screenshotStream : screenShotStreams) {
|
|
|
|
}
|
|
|
|
// try {
|
|
|
|
}
|
|
|
|
// screenshotName = Constants.IMAGE_ARTIFACTS[2] + count;
|
|
|
|
return applicationRelease;
|
|
|
|
// saveFile(screenshotStream, artifactDirectoryPath + File.separator + screenshotName);
|
|
|
|
} catch (IOException e) {
|
|
|
|
// count++;
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
// if (count > screenShotMaxCount) {
|
|
|
|
"IO Exception while saving the screens hots for the " + "application " + applicationId, e);
|
|
|
|
// log.error("Maximum limit for the screen-shot is " + screenShotMaxCount
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
// + " Cannot upload another screenshot for the application with the UUID "
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
// + applicationUUID);
|
|
|
|
throw new ApplicationStorageManagementException("Application Management DAO exception while trying to"
|
|
|
|
// break;
|
|
|
|
+ " update the screen-shot count for the application " + applicationId + " for the tenant "
|
|
|
|
// }
|
|
|
|
+ tenantId, e);
|
|
|
|
// } catch (IOException e) {
|
|
|
|
}
|
|
|
|
// throw new ApplicationStorageManagementException(
|
|
|
|
|
|
|
|
// "IO Exception while saving the screens hots for the " + "application " + applicationUUID,
|
|
|
|
|
|
|
|
// e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
// ApplicationManagementDAOFactory.getApplicationDAO().updateScreenShotCount(applicationUUID, tenantId, count - 1);
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
// } catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
// throw new ApplicationStorageManagementException("Transaction Management exception while trying to "
|
|
|
|
|
|
|
|
// + "update the screen-shot count of the application " + applicationUUID + " for the tenant "
|
|
|
|
|
|
|
|
// + tenantId, e);
|
|
|
|
|
|
|
|
// } catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
// throw new ApplicationStorageManagementException("Database connection management exception while "
|
|
|
|
|
|
|
|
// + "trying to update the screen-shot count for the application " + applicationUUID + " for the"
|
|
|
|
|
|
|
|
// + " tenant " + tenantId, e);
|
|
|
|
|
|
|
|
// } catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
// throw new ApplicationStorageManagementException("Application Management DAO exception while trying to"
|
|
|
|
|
|
|
|
// + " update the screen-shot count for the application " + applicationUUID + " for the tenant "
|
|
|
|
|
|
|
|
// + tenantId, e);
|
|
|
|
|
|
|
|
// } finally {
|
|
|
|
|
|
|
|
// ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void uploadReleaseArtifacts(String applicationUUID, String versionName, InputStream binaryFile)
|
|
|
|
public ApplicationRelease uploadReleaseArtifacts(int applicationId, ApplicationRelease applicationRelease , InputStream binaryFile)
|
|
|
|
throws ResourceManagementException {
|
|
|
|
throws ResourceManagementException {
|
|
|
|
Application application = validateApplication(applicationUUID);
|
|
|
|
|
|
|
|
String artifactDirectoryPath = storagePath + application.getId();
|
|
|
|
String artifactDirectoryPath;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
String md5OfApp;
|
|
|
|
log.debug("Artifact Directory Path for saving the application release related artifacts related with "
|
|
|
|
md5OfApp = getMD5(binaryFile);
|
|
|
|
+ "application " + applicationUUID + " is " + artifactDirectoryPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
if(validateApplication(applicationId) && md5OfApp != null){
|
|
|
|
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
|
|
|
|
artifactDirectoryPath = storagePath + md5OfApp;
|
|
|
|
if (binaryFile != null) {
|
|
|
|
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Artifact Directory Path for saving the application release related artifacts related with "
|
|
|
|
|
|
|
|
+ "application ID " + applicationId + " is " + artifactDirectoryPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
saveFile(binaryFile, artifactDirectoryPath + File.separator + versionName);
|
|
|
|
saveFile(binaryFile, artifactDirectoryPath);
|
|
|
|
|
|
|
|
applicationRelease.setAppStoredLoc(artifactDirectoryPath);
|
|
|
|
|
|
|
|
applicationRelease.setAppHashValue(md5OfApp);
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
"IO Exception while saving the release artifacts in the server for the application "
|
|
|
|
"IO Exception while saving the release artifacts in the server for the application "
|
|
|
|
+ applicationUUID, e);
|
|
|
|
+ applicationId, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
log.error("Verify application existence and md5sum value retrieving process");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return applicationRelease;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -278,24 +267,32 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* To validate the Application before storing and retrieving the artifacts of a particular application.
|
|
|
|
* To validate the Application before storing and retrieving the artifacts of a particular application.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param uuid UUID of the Application
|
|
|
|
* @param appId ID of the Application
|
|
|
|
* @return {@link Application} if it is validated
|
|
|
|
* @return {@link Application} if it is validated
|
|
|
|
* @throws ApplicationStorageManagementException Application Storage Management Exception will be thrown if a
|
|
|
|
* @throws ApplicationStorageManagementException Application Storage Management Exception will be thrown if a
|
|
|
|
* valid application related with the specific UUID
|
|
|
|
* valid application related with the specific UUID
|
|
|
|
* could not be found.
|
|
|
|
* could not be found.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Application validateApplication(String uuid) throws ApplicationStorageManagementException {
|
|
|
|
private Boolean validateApplication(int appId) throws ApplicationStorageManagementException {
|
|
|
|
Application application;
|
|
|
|
Boolean isAppExist;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
application = DataHolder.getInstance().getApplicationManager().getApplication(uuid);
|
|
|
|
isAppExist = DataHolder.getInstance().getApplicationManager().verifyApplicationExistenceById(appId);
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
"Exception while retrieving the application details for the application with UUID "
|
|
|
|
"Exception while verifing the application existence for the application with ID "+ appId);
|
|
|
|
+ uuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (application == null) {
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException("Application with UUID " + uuid + " does not exist.");
|
|
|
|
return isAppExist;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getMD5(InputStream binaryFile) throws ApplicationStorageManagementException {
|
|
|
|
|
|
|
|
String md5;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
md5 = DigestUtils.md5Hex(IOUtils.toByteArray(binaryFile));
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException
|
|
|
|
|
|
|
|
("IO Exception while trying to get the md5sum value of application");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return application;
|
|
|
|
return md5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|