|
|
@ -166,7 +166,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
changeLifecycleState(appId, applicationRelease.getUuid(), lifecycleState, false);
|
|
|
|
changeLifecycleState(appId, applicationRelease.getUuid(), lifecycleState, false, false);
|
|
|
|
|
|
|
|
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
applicationRelease.setLifecycleState(lifecycleState);
|
|
|
|
applicationReleases.add(applicationRelease);
|
|
|
|
applicationReleases.add(applicationRelease);
|
|
|
@ -244,18 +244,16 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
log.debug("Application release request is received for the application " + application.toString());
|
|
|
|
log.debug("Application release request is received for the application " + application.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.getDBConnection();
|
|
|
|
applicationRelease = this.applicationReleaseDAO
|
|
|
|
applicationRelease = this.applicationReleaseDAO
|
|
|
|
.createRelease(applicationRelease, application.getId(), tenantId);
|
|
|
|
.createRelease(applicationRelease, application.getId(), tenantId);
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
|
|
|
|
changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState, true);
|
|
|
|
changeLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState, true,
|
|
|
|
|
|
|
|
false);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
"Error occurred while adding application release into IoTS app management Application id of the "
|
|
|
|
"Error occurred while adding application release into IoTS app management Application id of the "
|
|
|
|
+ "application release: " + applicationId, e);
|
|
|
|
+ "application release: " + applicationId, e);
|
|
|
@ -502,7 +500,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
"You don't have permission to delete this application. In order to delete an application you " +
|
|
|
|
"You don't have permission to delete this application. In order to delete an application you " +
|
|
|
|
"need to have admin permission");
|
|
|
|
"need to have admin permission");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
application = getApplicationIfAccessible(applicationId);
|
|
|
|
application = getApplicationIfAccessible(applicationId);
|
|
|
|
if ( application == null) {
|
|
|
|
if ( application == null) {
|
|
|
|
throw new ApplicationManagementException("Invalid Application");
|
|
|
|
throw new ApplicationManagementException("Invalid Application");
|
|
|
@ -512,16 +510,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
log.debug("Request is received to delete applications which are related with the application id " +
|
|
|
|
log.debug("Request is received to delete applications which are related with the application id " +
|
|
|
|
applicationId);
|
|
|
|
applicationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
for (ApplicationRelease applicationRelease : applicationReleases) {
|
|
|
|
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
|
|
|
|
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true);
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true, false);
|
|
|
|
storedLocations.add(applicationRelease.getAppHashValue());
|
|
|
|
storedLocations.add(applicationRelease.getAppHashValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
this.applicationDAO.deleteApplication(applicationId);
|
|
|
|
this.applicationDAO.deleteApplication(applicationId);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Error occured while check whether current user has the permission to delete an application";
|
|
|
|
String msg = "Error occured while check whether current user has the permission to delete an application";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -533,28 +532,37 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String deleteApplicationRelease(int applicationId, String releaseUuid)
|
|
|
|
public String deleteApplicationRelease(int applicationId, String releaseUuid, boolean handleConnections)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
Application application = getApplicationIfAccessible(applicationId);
|
|
|
|
Application application = getApplicationIfAccessible(applicationId);
|
|
|
|
if (application == null) {
|
|
|
|
if (application == null) {
|
|
|
|
throw new ApplicationManagementException("Invalid Application ID is received");
|
|
|
|
throw new ApplicationManagementException("Invalid Application ID is received");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid);
|
|
|
|
if (handleConnections) {
|
|
|
|
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
String currentState = appLifecycleState.getCurrentState();
|
|
|
|
}
|
|
|
|
if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState
|
|
|
|
try {
|
|
|
|
.REJECTED.toString().equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals
|
|
|
|
ApplicationRelease applicationRelease = getAppReleaseIfExists(applicationId, releaseUuid);
|
|
|
|
(currentState) ) {
|
|
|
|
LifecycleState appLifecycleState = getLifecycleState(applicationId, applicationRelease.getUuid());
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
String currentState = appLifecycleState.getCurrentState();
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
if (AppLifecycleState.DEPRECATED.toString().equals(currentState) || AppLifecycleState
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
.REJECTED.toString().equals(currentState) || AppLifecycleState.UNPUBLISHED.toString().equals
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true);
|
|
|
|
(currentState)) {
|
|
|
|
}else{
|
|
|
|
LifecycleState newAppLifecycleState = new LifecycleState();
|
|
|
|
throw new ApplicationManagementException("Can't delete the application release, You have to move the " +
|
|
|
|
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
|
|
|
|
"lifecycle state from "+ currentState + " to acceptable " +
|
|
|
|
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
|
|
|
|
"state") ;
|
|
|
|
changeLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState, true, false);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new ApplicationManagementException("Can't delete the application release, You have to move the " +
|
|
|
|
|
|
|
|
"lifecycle state from " + currentState + " to acceptable " +
|
|
|
|
|
|
|
|
"state");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return applicationRelease.getAppHashValue();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (handleConnections) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationRelease.getAppHashValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -856,12 +864,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleState state, Boolean checkExist)
|
|
|
|
public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleState state, Boolean checkExist,
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
Boolean handleDBConnections) throws ApplicationManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
if (checkExist) {
|
|
|
|
if (checkExist) {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
if (handleDBConnections) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!this.applicationDAO.verifyApplicationExistenceById(applicationId, tenantId)){
|
|
|
|
if (!this.applicationDAO.verifyApplicationExistenceById(applicationId, tenantId)){
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(
|
|
|
|
"Couldn't found application for the application Id: " + applicationId);
|
|
|
|
"Couldn't found application for the application Id: " + applicationId);
|
|
|
@ -879,11 +889,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
|
|
|
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
|
|
|
if (getLifecycleManagementService()
|
|
|
|
if (getLifecycleManagementService()
|
|
|
|
.isValidStateChange(state.getPreviousState(), state.getCurrentState())) {
|
|
|
|
.isValidStateChange(state.getPreviousState(), state.getCurrentState())) {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
//todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there
|
|
|
|
//todo if current state of the adding lifecycle state is PUBLISHED, need to check whether is there
|
|
|
|
//todo any other application release in PUBLISHED state for the application( i.e for the appid)
|
|
|
|
//todo any other application release in PUBLISHED state for the application( i.e for the appid)
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId);
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'" + " to '"
|
|
|
|
log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'" + " to '"
|
|
|
|
+ state.getCurrentState() + "'");
|
|
|
|
+ state.getCurrentState() + "'");
|
|
|
@ -892,12 +900,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
"Failed to add lifecycle state. Application Id: " + applicationId + " Application release UUID: "
|
|
|
|
"Failed to add lifecycle state. Application Id: " + applicationId + " Application release UUID: "
|
|
|
|
+ releaseUuid, e);
|
|
|
|
+ releaseUuid, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
if (handleDBConnections) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|