|
|
|
@ -102,11 +102,15 @@ import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
@ -727,20 +731,23 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
|
|
|
|
|
byte[] content = getByteContentOfApp(applicationArtifact);
|
|
|
|
|
String md5OfApp = generateMD5OfApp(applicationArtifact, content);
|
|
|
|
|
try {
|
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
|
|
|
|
|
validateReleaseBinaryFileHash(md5OfApp);
|
|
|
|
|
releaseDTO.setUuid(UUID.randomUUID().toString());
|
|
|
|
|
releaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
releaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
|
applicationStorageManager.uploadReleaseArtifact(releaseDTO, deviceType,
|
|
|
|
|
binaryDuplicate, tenantId);
|
|
|
|
|
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
String msg = "Error occurred when uploading release artifact into the server";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
@ -856,15 +863,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
applicationReleaseDTO.setUuid(uuid);
|
|
|
|
|
|
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
|
try {
|
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
|
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
|
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
|
|
|
|
|
if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
|
|
|
|
|
ApplicationInstaller applicationInstaller = applicationStorageManager
|
|
|
|
|
.getAppInstallerData(binary, deviceType);
|
|
|
|
|
.getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
|
|
|
|
|
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
|
|
|
|
applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
|
|
|
|
|
} else {
|
|
|
|
@ -892,7 +896,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
log.error(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) {
|
|
|
|
|
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
|
|
|
|
+ applicationReleaseDTO.getUuid();
|
|
|
|
@ -907,10 +911,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
}
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
|
applicationStorageManager
|
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate, tenantId);
|
|
|
|
|
}
|
|
|
|
|
.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();
|
|
|
|
@ -929,9 +932,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} 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();
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
@ -957,23 +959,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
|
|
|
|
|
// The application executable artifacts such as apks are uploaded.
|
|
|
|
|
try {
|
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
|
|
|
|
|
|
try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
|
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(binaryClone);
|
|
|
|
|
|
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
|
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
|
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);
|
|
|
|
|
.getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
|
|
|
|
|
String packageName = applicationInstaller.getPackageName();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -1003,13 +1000,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
applicationReleaseDTO.setPackageName(packageName);
|
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
|
|
|
|
|
applicationReleaseDTO.setAppHashValue(md5OfApp);
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
|
applicationStorageManager
|
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate,
|
|
|
|
|
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.";
|
|
|
|
@ -1024,15 +1019,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for application "
|
|
|
|
|
+ "release UUID " + applicationReleaseDTO.getUuid();
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationStorageManagementException(msg, 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();
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new ApplicationStorageManagementException(msg, e);
|
|
|
|
@ -3607,15 +3600,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
|
// The application executable artifacts such as deb are uploaded.
|
|
|
|
|
try {
|
|
|
|
|
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
|
|
|
|
try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
|
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(binaryClone);
|
|
|
|
|
String md5OfApp = applicationStorageManager.getMD5(
|
|
|
|
|
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
|
|
|
|
|
if (md5OfApp == null) {
|
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for "
|
|
|
|
|
+ "application release UUID " + applicationReleaseDTO.get().getUuid();
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ApplicationStorageManagementException(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!applicationReleaseDTO.get().getAppHashValue().equals(md5OfApp)) {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
@ -3632,13 +3625,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
applicationReleaseDTO.get().setInstallerName(applicationArtifact.getInstallerName());
|
|
|
|
|
String deletingAppHashValue = applicationReleaseDTO.get().getAppHashValue();
|
|
|
|
|
applicationReleaseDTO.get().setAppHashValue(md5OfApp);
|
|
|
|
|
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
|
|
|
|
|
applicationStorageManager
|
|
|
|
|
.uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
|
|
|
|
|
binaryDuplicate, tenantId);
|
|
|
|
|
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.";
|
|
|
|
@ -3654,7 +3645,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (StorageManagementException e) {
|
|
|
|
|
String msg = "Error occurred while retrieving md5sum value from the binary file for "
|
|
|
|
|
+ "application release UUID " + applicationReleaseDTO.get().getUuid();
|
|
|
|
|