|
|
@ -117,8 +117,6 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
count++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
@ -127,6 +125,31 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw new ApplicationStorageManagementException("Application Management DAO exception while trying to "
|
|
|
|
throw new ApplicationStorageManagementException("Application Management DAO exception while trying to "
|
|
|
|
|
|
|
|
+ "update the screen-shot count for the application " + applicationId + " for the tenant id "
|
|
|
|
|
|
|
|
+ tenantId, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public ApplicationRelease updateImageArtifacts(int applicationId, String uuid, InputStream iconFileStream,
|
|
|
|
|
|
|
|
InputStream bannerFileStream, List<InputStream> screenShotStreams)
|
|
|
|
|
|
|
|
throws ResourceManagementException, ApplicationManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ApplicationRelease applicationRelease = validateApplicationRelease(uuid);
|
|
|
|
|
|
|
|
applicationRelease = uploadImageArtifacts(applicationId, applicationRelease, iconFileStream, bannerFileStream, screenShotStreams);
|
|
|
|
|
|
|
|
return applicationRelease;
|
|
|
|
|
|
|
|
} catch (ApplicationStorageManagementException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
throw new ApplicationStorageManagementException("Application Storage exception while trying to"
|
|
|
|
|
|
|
|
+ " update the screen-shot count for the application " + applicationId + " for the tenant "
|
|
|
|
|
|
|
|
+ tenantId, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
throw new ApplicationManagementException("Application Management DAO exception while trying to"
|
|
|
|
+ " update the screen-shot count for the application " + applicationId + " for the tenant "
|
|
|
|
+ " update the screen-shot count for the application " + applicationId + " for the tenant "
|
|
|
|
+ tenantId, e);
|
|
|
|
+ tenantId, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -167,100 +190,125 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
|
|
|
|
public ApplicationRelease updateReleaseArtifacts(int applicationId, String applicationUuid, InputStream binaryFile)
|
|
|
|
throws ApplicationStorageManagementException {
|
|
|
|
throws ResourceManagementException {
|
|
|
|
// todo this should be validate application release
|
|
|
|
|
|
|
|
Application application = validateApplication(applicationUUID);
|
|
|
|
|
|
|
|
String artifactPath = storagePath + application.getId() + File.separator + versionName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File binaryFile = new File(artifactPath);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
|
|
|
|
if (!binaryFile.exists()) {
|
|
|
|
ApplicationRelease applicationRelease = null;
|
|
|
|
throw new ApplicationStorageManagementException("Binary file does not exist for this release");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return new FileInputStream(artifactPath);
|
|
|
|
applicationRelease = validateApplicationRelease(applicationUuid);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
applicationRelease = uploadReleaseArtifacts(applicationId, applicationRelease,binaryFile);
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
return applicationRelease;
|
|
|
|
"Binary file does not exist for the version " + versionName + " for the application ", e);
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
}
|
|
|
|
throw new ApplicationStorageManagementException("Application Management exception while trying to"
|
|
|
|
|
|
|
|
+ " update the Application artifact for the application " + applicationId + " for the tenant "
|
|
|
|
|
|
|
|
+ tenantId, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public InputStream getReleasedArtifacts(String applicationUUID, String versionName)
|
|
|
|
|
|
|
|
throws ApplicationStorageManagementException {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// todo this should be validate application release
|
|
|
|
|
|
|
|
// Application application = validateApplication(applicationUUID);
|
|
|
|
|
|
|
|
// String artifactPath = storagePath + application.getId() + File.separator + versionName;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
// log.debug("ApplicationRelease artifacts are searched in the location " + artifactPath);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// File binaryFile = new File(artifactPath);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (!binaryFile.exists()) {
|
|
|
|
|
|
|
|
// throw new ApplicationStorageManagementException("Binary file does not exist for this release");
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// return new FileInputStream(artifactPath);
|
|
|
|
|
|
|
|
// } catch (FileNotFoundException e) {
|
|
|
|
|
|
|
|
// throw new ApplicationStorageManagementException(
|
|
|
|
|
|
|
|
// "Binary file does not exist for the version " + versionName + " for the application ", e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException {
|
|
|
|
public void deleteApplicationArtifacts(String applicationUUID) throws ApplicationStorageManagementException {
|
|
|
|
// todo this should be validate application release
|
|
|
|
// todo this should be validate application release
|
|
|
|
Application application = validateApplication(applicationUUID);
|
|
|
|
// Application application = validateApplication(applicationUUID);
|
|
|
|
String artifactDirectoryPath = storagePath + application.getId();
|
|
|
|
// String artifactDirectoryPath = storagePath + application.getId();
|
|
|
|
File artifactDirectory = new File(artifactDirectoryPath);
|
|
|
|
// File artifactDirectory = new File(artifactDirectoryPath);
|
|
|
|
|
|
|
|
//
|
|
|
|
if (artifactDirectory.exists()) {
|
|
|
|
// if (artifactDirectory.exists()) {
|
|
|
|
StorageManagementUtil.deleteDir(artifactDirectory);
|
|
|
|
// StorageManagementUtil.deleteDir(artifactDirectory);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
|
|
|
|
public void deleteApplicationReleaseArtifacts(String applicationUUID, String version)
|
|
|
|
throws ApplicationStorageManagementException {
|
|
|
|
throws ApplicationStorageManagementException {
|
|
|
|
// todo this should be validate application release
|
|
|
|
// todo this should be validate application release
|
|
|
|
Application application = validateApplication(applicationUUID);
|
|
|
|
// Application application = validateApplication(applicationUUID);
|
|
|
|
String artifactPath = storagePath + application.getId() + File.separator + version;
|
|
|
|
// String artifactPath = storagePath + application.getId() + File.separator + version;
|
|
|
|
File artifact = new File(artifactPath);
|
|
|
|
// File artifact = new File(artifactPath);
|
|
|
|
|
|
|
|
//
|
|
|
|
if (artifact.exists()) {
|
|
|
|
// if (artifact.exists()) {
|
|
|
|
StorageManagementUtil.deleteDir(artifact);
|
|
|
|
// StorageManagementUtil.deleteDir(artifact);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws
|
|
|
|
public void deleteAllApplicationReleaseArtifacts(String applicationUUID) throws
|
|
|
|
ApplicationStorageManagementException {
|
|
|
|
ApplicationStorageManagementException {
|
|
|
|
// todo this should be validate application release
|
|
|
|
// todo this should be validate application release
|
|
|
|
validateApplication(applicationUUID);
|
|
|
|
// validateApplication(applicationUUID);
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
List<ApplicationRelease> applicationReleases = DataHolder.getInstance().getApplicationReleaseManager()
|
|
|
|
// List<ApplicationRelease> applicationReleases = DataHolder.getInstance().getApplicationReleaseManager()
|
|
|
|
.getReleases(applicationUUID);
|
|
|
|
// .getReleases(applicationUUID);
|
|
|
|
for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
// for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
deleteApplicationReleaseArtifacts(applicationUUID, applicationRelease.getVersion());
|
|
|
|
// deleteApplicationReleaseArtifacts(applicationUUID, applicationRelease.getVersion());
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
// } catch (ApplicationManagementException e) {
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
// throw new ApplicationStorageManagementException(
|
|
|
|
"Application Management Exception while getting releases " + "for the application "
|
|
|
|
// "Application Management Exception while getting releases " + "for the application "
|
|
|
|
+ applicationUUID, e);
|
|
|
|
// + applicationUUID, e);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws
|
|
|
|
public ImageArtifact getImageArtifact(String applicationUUID, String name, int count) throws
|
|
|
|
ApplicationStorageManagementException {
|
|
|
|
ApplicationStorageManagementException {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
// todo this should be validate application release
|
|
|
|
// todo this should be validate application release
|
|
|
|
Application application = validateApplication(applicationUUID);
|
|
|
|
// Application application = validateApplication(applicationUUID);
|
|
|
|
validateImageArtifactNames(name);
|
|
|
|
// validateImageArtifactNames(name);
|
|
|
|
String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase();
|
|
|
|
// String imageArtifactPath = storagePath + application.getId() + File.separator + name.toLowerCase();
|
|
|
|
|
|
|
|
//
|
|
|
|
if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) {
|
|
|
|
// if (name.equalsIgnoreCase(Constants.IMAGE_ARTIFACTS[2])) {
|
|
|
|
imageArtifactPath += count;
|
|
|
|
// imageArtifactPath += count;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
File imageFile = new File(imageArtifactPath);
|
|
|
|
// File imageFile = new File(imageArtifactPath);
|
|
|
|
if (!imageFile.exists()) {
|
|
|
|
// if (!imageFile.exists()) {
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
// throw new ApplicationStorageManagementException(
|
|
|
|
"Image artifact " + name + " does not exist for the " + "application with UUID " + applicationUUID);
|
|
|
|
// "Image artifact " + name + " does not exist for the " + "application with UUID " + applicationUUID);
|
|
|
|
} else {
|
|
|
|
// } else {
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
return StorageManagementUtil.createImageArtifact(imageFile, imageArtifactPath);
|
|
|
|
// return StorageManagementUtil.createImageArtifact(imageFile, imageArtifactPath);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
// } catch (FileNotFoundException e) {
|
|
|
|
throw new ApplicationStorageManagementException(
|
|
|
|
// throw new ApplicationStorageManagementException(
|
|
|
|
"File not found exception while trying to get the image artifact " + name + " for the "
|
|
|
|
// "File not found exception while trying to get the image artifact " + name + " for the "
|
|
|
|
+ "application " + applicationUUID, e);
|
|
|
|
// + "application " + applicationUUID, e);
|
|
|
|
} catch (IOException e) {
|
|
|
|
// } catch (IOException e) {
|
|
|
|
throw new ApplicationStorageManagementException("IO Exception while trying to detect the image "
|
|
|
|
// throw new ApplicationStorageManagementException("IO Exception while trying to detect the image "
|
|
|
|
+ "artifact " + name + " for the application " + applicationUUID, e);
|
|
|
|
// + "artifact " + name + " for the application " + applicationUUID, e);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -311,7 +359,8 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
|
|
|
|
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
|
|
|
|
throw new ApplicationManagementException("Application UUID is null. Application UUID is a required "
|
|
|
|
+ "parameter to get the relevant application.");
|
|
|
|
+ "parameter to get the relevant application.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().getRelease();
|
|
|
|
ApplicationRelease applicationRelease = DataHolder.getInstance().getApplicationReleaseManager().
|
|
|
|
|
|
|
|
getReleaseByUuid(applicationUuid);
|
|
|
|
if (applicationRelease == null) {
|
|
|
|
if (applicationRelease == null) {
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(
|
|
|
|
"Application with UUID " + applicationUuid + " does not exist.");
|
|
|
|
"Application with UUID " + applicationUuid + " does not exist.");
|
|
|
|