|
|
@ -102,11 +102,15 @@ import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
@ -727,20 +731,23 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
byte[] content = getByteContentOfApp(applicationArtifact);
|
|
|
|
try {
|
|
|
|
String md5OfApp = generateMD5OfApp(applicationArtifact, content);
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
|
|
|
|
validateReleaseBinaryFileHash(md5OfApp);
|
|
|
|
validateReleaseBinaryFileHash(md5OfApp);
|
|
|
|
releaseDTO.setUuid(UUID.randomUUID().toString());
|
|
|
|
releaseDTO.setUuid(UUID.randomUUID().toString());
|
|
|
|
releaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
releaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
releaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
releaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
applicationStorageManager.uploadReleaseArtifact(releaseDTO, deviceType,
|
|
|
|
applicationStorageManager.uploadReleaseArtifact(releaseDTO, deviceType,
|
|
|
|
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
|
|
|
|
binaryDuplicate, tenantId);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
String msg = "Error occurred when uploading release artifact into the server";
|
|
|
|
String msg = "Error occurred when uploading release artifact into the server";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
|
|
|
|
|
|
|
+ releaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addImageArtifacts(releaseDTO, applicationArtifact, tenantId);
|
|
|
|
return addImageArtifacts(releaseDTO, applicationArtifact, tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -856,82 +863,77 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
|
|
|
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
|
|
|
|
if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
|
|
|
|
if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
|
|
|
|
ApplicationInstaller applicationInstaller = applicationStorageManager
|
|
|
|
ApplicationInstaller applicationInstaller = applicationStorageManager
|
|
|
|
.getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
|
|
|
|
.getAppInstallerData(binary, deviceType);
|
|
|
|
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
|
|
|
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
|
|
|
applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
|
|
|
|
applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
String windowsInstallerName = applicationArtifact.getInstallerName();
|
|
|
|
String windowsInstallerName = applicationArtifact.getInstallerName();
|
|
|
|
String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
|
|
|
|
String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
|
|
|
|
if (!extension.equalsIgnoreCase(Constants.MSI) &&
|
|
|
|
if (!extension.equalsIgnoreCase(Constants.MSI) &&
|
|
|
|
!extension.equalsIgnoreCase(Constants.APPX)) {
|
|
|
|
!extension.equalsIgnoreCase(Constants.APPX)) {
|
|
|
|
String msg = "Application Type doesn't match with supporting application types of " +
|
|
|
|
String msg = "Application Type doesn't match with supporting application types of " +
|
|
|
|
deviceType + "platform which are APPX and MSI";
|
|
|
|
deviceType + "platform which are APPX and MSI";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String packageName = applicationReleaseDTO.getPackageName();
|
|
|
|
String packageName = applicationReleaseDTO.getPackageName();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
if (!isNewRelease && applicationReleaseDAO
|
|
|
|
if (!isNewRelease && applicationReleaseDAO
|
|
|
|
.isActiveReleaseExisitForPackageName(packageName, tenantId,
|
|
|
|
.isActiveReleaseExisitForPackageName(packageName, tenantId,
|
|
|
|
lifecycleStateManager.getEndState())) {
|
|
|
|
lifecycleStateManager.getEndState())) {
|
|
|
|
String msg = "Application release is already exist for the package name: " + packageName
|
|
|
|
String msg = "Application release is already exist for the package name: " + packageName
|
|
|
|
+ ". Either you can delete all application releases for package " + packageName + " or "
|
|
|
|
+ ". Either you can delete all application releases for package " + packageName + " or "
|
|
|
|
+ "you can add this app release as an new application release, under the existing "
|
|
|
|
+ "you can add this app release as an new application release, under the existing "
|
|
|
|
+ "application.";
|
|
|
|
+ "application.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(new ByteArrayInputStream(content));
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
|
|
|
|
|
|
|
+ applicationReleaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Application release exists for the uploaded binary file. Device Type: " + deviceType;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
|
|
|
|
applicationStorageManager
|
|
|
|
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate, tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
|
|
|
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
|
|
|
+ applicationReleaseDTO.getUuid();
|
|
|
|
+ applicationReleaseDTO.getUuid();
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
}
|
|
|
|
String msg = "Error occurred when getting database connection for verifying app release data.";
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
String msg =
|
|
|
|
"Error occurred when executing the query for verifying application release existence for "
|
|
|
|
"Application release exists for the uploaded binary file. Device Type: " + deviceType;
|
|
|
|
+ "the package.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationStorageManager
|
|
|
|
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType,
|
|
|
|
|
|
|
|
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
|
|
|
|
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
|
|
|
|
|
|
|
+ applicationReleaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting database connection for verifying app release data.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error occurred when executing the query for verifying application release existence for "
|
|
|
|
|
|
|
|
+ "the package.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
|
|
|
|
String msg = "Error occurred when getting file input stream. Installer name: " + applicationArtifact
|
|
|
|
.getInstallerName();
|
|
|
|
.getInstallerName();
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
@ -957,73 +959,64 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
|
|
|
|
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for application "
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(binaryClone);
|
|
|
|
+ "release UUID " + applicationReleaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for application "
|
|
|
|
}
|
|
|
|
+ "release UUID " + applicationReleaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
|
|
|
|
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
|
|
|
|
|
|
|
|
ApplicationInstaller applicationInstaller = applicationStorageManager
|
|
|
|
|
|
|
|
.getAppInstallerData(binary, deviceType);
|
|
|
|
|
|
|
|
String packageName = applicationInstaller.getPackageName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
ApplicationInstaller applicationInstaller = applicationStorageManager
|
|
|
|
String msg = "Same binary file is in the server. Hence you can't add same file into the "
|
|
|
|
.getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
|
|
|
|
+ "server. Device Type: " + deviceType + " and package name: " + packageName;
|
|
|
|
String packageName = applicationInstaller.getPackageName();
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (applicationReleaseDTO.getPackageName() == null){
|
|
|
|
|
|
|
|
String msg = "Found null value for application release package name for application "
|
|
|
|
|
|
|
|
+ "release which has UUID: " + applicationReleaseDTO.getUuid();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applicationReleaseDTO.getPackageName().equals(packageName)){
|
|
|
|
|
|
|
|
String msg = "Package name of the new artifact does not match with the package name of "
|
|
|
|
|
|
|
|
+ "the exiting application release. Package name of the existing app release "
|
|
|
|
|
|
|
|
+ applicationReleaseDTO.getPackageName() + " and package name of the new "
|
|
|
|
|
|
|
|
+ "application release " + packageName;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
|
|
|
try {
|
|
|
|
applicationReleaseDTO.setPackageName(packageName);
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
String msg = "Same binary file is in the server. Hence you can't add same file into the "
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
+ "server. Device Type: " + deviceType + " and package name: " + packageName;
|
|
|
|
applicationStorageManager
|
|
|
|
log.error(msg);
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate,
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
tenantId);
|
|
|
|
}
|
|
|
|
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
|
|
|
|
if (applicationReleaseDTO.getPackageName() == null){
|
|
|
|
applicationReleaseDTO, tenantId);
|
|
|
|
String msg = "Found null value for application release package name for application "
|
|
|
|
}
|
|
|
|
+ "release which has UUID: " + applicationReleaseDTO.getUuid();
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
log.error(msg);
|
|
|
|
String msg = "Error occurred when getting database connection for verifying application "
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
+ "release existing for new app hash value.";
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
if (!applicationReleaseDTO.getPackageName().equals(packageName)){
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
String msg = "Package name of the new artifact does not match with the package name of "
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
+ "the exiting application release. Package name of the existing app release "
|
|
|
|
String msg = "Error occurred when executing the query for verifying application release "
|
|
|
|
+ applicationReleaseDTO.getPackageName() + " and package name of the new "
|
|
|
|
+ "existence for the new app hash value.";
|
|
|
|
+ "application release " + packageName;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
|
|
|
|
|
|
|
applicationReleaseDTO.setPackageName(packageName);
|
|
|
|
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
|
|
|
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
|
|
|
applicationStorageManager.uploadReleaseArtifact(applicationReleaseDTO, deviceType,
|
|
|
|
|
|
|
|
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())),
|
|
|
|
|
|
|
|
tenantId);
|
|
|
|
|
|
|
|
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
|
|
|
|
|
|
|
|
applicationReleaseDTO, tenantId);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting database connection for verifying application "
|
|
|
|
|
|
|
|
+ "release existing for new app hash value.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when executing the query for verifying application release "
|
|
|
|
|
|
|
|
+ "existence for the new app hash value.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
@ -1032,7 +1025,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
|
|
|
|
String msg = "Error occurred when getting file input stream. Installer name: " + applicationArtifact
|
|
|
|
.getInstallerName();
|
|
|
|
.getInstallerName();
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
@ -3607,52 +3600,49 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
// The application executable artifacts such as deb are uploaded.
|
|
|
|
// The application executable artifacts such as deb are uploaded.
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(
|
|
|
|
try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
|
|
|
|
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(binaryClone);
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for "
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for "
|
|
|
|
+ "application release UUID " + applicationReleaseDTO.get().getUuid();
|
|
|
|
+ "application release UUID " + applicationReleaseDTO.get().getUuid();
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applicationReleaseDTO.get().getAppHashValue().equals(md5OfApp)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Same binary file is in the server. Hence you can't add same file into the "
|
|
|
|
|
|
|
|
+ "server. Device Type: " + deviceTypeObj.getName()
|
|
|
|
|
|
|
|
+ " and package name: " + applicationDTO.getApplicationReleaseDTOs()
|
|
|
|
|
|
|
|
.get(0).getPackageName();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
if (!applicationReleaseDTO.get().getAppHashValue().equals(md5OfApp)) {
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.get().getAppHashValue();
|
|
|
|
try {
|
|
|
|
applicationReleaseDTO.get().setAppHashValue(md5OfApp);
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
|
|
|
|
applicationStorageManager
|
|
|
|
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
|
|
|
|
|
|
|
|
binaryDuplicate, tenantId);
|
|
|
|
|
|
|
|
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
|
|
|
|
|
|
|
|
applicationReleaseDTO.get(), tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting database connection for verifying application"
|
|
|
|
|
|
|
|
+ " release existing for new app hash value.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
String msg =
|
|
|
|
"Error occurred when executing the query for verifying application release "
|
|
|
|
"Same binary file is in the server. Hence you can't add same file into the "
|
|
|
|
+ "existence for the new app hash value.";
|
|
|
|
+ "server. Device Type: " + deviceTypeObj.getName()
|
|
|
|
log.error(msg, e);
|
|
|
|
+ " and package name: " + applicationDTO.getApplicationReleaseDTOs()
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
.get(0).getPackageName();
|
|
|
|
} finally {
|
|
|
|
log.error(msg);
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.get().getAppHashValue();
|
|
|
|
|
|
|
|
applicationReleaseDTO.get().setAppHashValue(md5OfApp);
|
|
|
|
|
|
|
|
applicationStorageManager.
|
|
|
|
|
|
|
|
uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
|
|
|
|
|
|
|
|
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
|
|
|
|
|
|
|
|
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
|
|
|
|
|
|
|
|
applicationReleaseDTO.get(), tenantId);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when getting database connection for verifying application"
|
|
|
|
|
|
|
|
+ " release existing for new app hash value.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error occurred when executing the query for verifying application release "
|
|
|
|
|
|
|
|
+ "existence for the new app hash value.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|