|
|
@ -39,7 +39,7 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Filter;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Filter;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.LifecycleStateDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationStorageManagementException;
|
|
|
@ -311,10 +311,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
applicationReleaseDTO.setCurrentState(initialLifecycleState);
|
|
|
|
applicationReleaseDTO.setCurrentState(initialLifecycleState);
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
.createRelease(applicationReleaseDTO, appId, tenantId);
|
|
|
|
.createRelease(applicationReleaseDTO, appId, tenantId);
|
|
|
|
LifecycleStateDTO lifecycleStateDTO = getLifecycleStateInstance(initialLifecycleState,
|
|
|
|
LifecycleState lifecycleState = getLifecycleStateInstance(initialLifecycleState,
|
|
|
|
initialLifecycleState);
|
|
|
|
initialLifecycleState);
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
.addLifecycleState(lifecycleStateDTO, appId, applicationReleaseDTO.getUuid(), tenantId);
|
|
|
|
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
applicationReleaseEntities.add(applicationReleaseDTO);
|
|
|
|
applicationReleaseEntities.add(applicationReleaseDTO);
|
|
|
|
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
|
|
|
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
|
|
|
|
Application application = appDtoToAppResponse(applicationDTO);
|
|
|
|
Application application = appDtoToAppResponse(applicationDTO);
|
|
|
@ -745,11 +745,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
String initialstate = lifecycleStateManager.getInitialState();
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
|
applicationReleaseDTO.setCurrentState(initialstate);
|
|
|
|
LifecycleStateDTO lifecycleState = getLifecycleStateInstance(initialstate, initialstate);
|
|
|
|
LifecycleState lifecycleState = getLifecycleStateInstance(initialstate, initialstate);
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
|
|
|
|
.createRelease(applicationReleaseDTO, applicationDTO.getId(), tenantId);
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
this.lifecycleStateDAO
|
|
|
|
.addLifecycleState(lifecycleState, applicationId, applicationReleaseDTO.getUuid(), tenantId);
|
|
|
|
.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
applicationRelease = releaseDtoToRelease(applicationReleaseDTO);
|
|
|
|
applicationRelease = releaseDtoToRelease(applicationReleaseDTO);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
return applicationRelease;
|
|
|
|
return applicationRelease;
|
|
|
@ -1116,7 +1116,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
throw new ApplicationManagementException("");
|
|
|
|
throw new ApplicationManagementException("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (ApplicationReleaseDTO applicationRelease : applicationReleases) {
|
|
|
|
for (ApplicationReleaseDTO applicationRelease : applicationReleases) {
|
|
|
|
LifecycleStateDTO lifecycleState = null;
|
|
|
|
LifecycleState lifecycleState = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
|
|
|
|
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
@ -1139,7 +1139,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// if (state != null && !state.isEmpty()) {
|
|
|
|
// if (state != null && !state.isEmpty()) {
|
|
|
|
// for (ApplicationReleaseDTO applicationRelease : applicationReleases) {
|
|
|
|
// for (ApplicationReleaseDTO applicationRelease : applicationReleases) {
|
|
|
|
// if (state.equals(applicationRelease.getLifecycleState().getCurrentState())) {
|
|
|
|
// if (state.equals(applicationRelease.getLifecycleStateChangeFlow().getCurrentState())) {
|
|
|
|
// filteredReleases.add(applicationRelease);
|
|
|
|
// filteredReleases.add(applicationRelease);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -1147,9 +1147,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
// if (AppLifecycleState.PUBLISHED.toString().equals(state) && filteredReleases.size() > 1) {
|
|
|
|
// if (AppLifecycleState.PUBLISHED.toString().equals(state) && filteredReleases.size() > 1) {
|
|
|
|
// log.warn("There are more than one application releases is found which is in PUBLISHED state");
|
|
|
|
// log.warn("There are more than one application releases is found which is in PUBLISHED state");
|
|
|
|
// filteredReleases.sort((r1, r2) -> {
|
|
|
|
// filteredReleases.sort((r1, r2) -> {
|
|
|
|
// if (r1.getLifecycleState().getUpdatedAt().after(r2.getLifecycleState().getUpdatedAt())) {
|
|
|
|
// if (r1.getLifecycleStateChangeFlow().getUpdatedAt().after(r2.getLifecycleStateChangeFlow().getUpdatedAt())) {
|
|
|
|
// return -1;
|
|
|
|
// return -1;
|
|
|
|
// } else if (r2.getLifecycleState().getUpdatedAt().after(r1.getLifecycleState().getUpdatedAt())) {
|
|
|
|
// } else if (r2.getLifecycleStateChangeFlow().getUpdatedAt().after(r1.getLifecycleStateChangeFlow().getUpdatedAt())) {
|
|
|
|
// return 1;
|
|
|
|
// return 1;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return 0;
|
|
|
|
// return 0;
|
|
|
@ -1327,17 +1327,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
|
|
|
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
|
|
|
|
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
|
|
|
|
.getDeviceSubscriptions(applicationReleaseDTO.getId(), tenantId);
|
|
|
|
for (DeviceSubscriptionDTO deviceSubscriptionDTO : deviceSubscriptionDTOS) {
|
|
|
|
if (!deviceSubscriptionDTOS.isEmpty()){
|
|
|
|
if (!deviceSubscriptionDTO.isUnsubscribed()) {
|
|
|
|
String msg = "Application release which has UUID: " + applicationReleaseDTO.getUuid() +
|
|
|
|
String msg = "This application is subscribed to device/s. Therefore you are not permitted to delete "
|
|
|
|
" either subscribed to device/s or it had subscribed to device/s. Therefore you are not "
|
|
|
|
+ "the application release.";
|
|
|
|
+ "permitted to delete the application release.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
|
|
|
|
applicationStorageManager.deleteApplicationReleaseArtifacts(applicationReleaseDTO.getAppHashValue());
|
|
|
|
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
|
|
|
|
lifecycleStateDAO.deleteLifecycleStateByReleaseId(applicationReleaseDTO.getId());
|
|
|
|
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
|
|
|
|
applicationReleaseDAO.deleteRelease(applicationReleaseDTO.getId());
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
String msg = "Error occurred when application release data for application release UUID: " + releaseUuid;
|
|
|
|
String msg = "Error occurred when application release data for application release UUID: " + releaseUuid;
|
|
|
@ -1565,72 +1565,84 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public LifecycleStateDTO getLifecycleState(int applicationId, String releaseUuid)
|
|
|
|
public List<LifecycleState> getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
LifecycleStateDTO lifecycleState;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid);
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
if (lifecycleState == null) {
|
|
|
|
.getReleaseByUUID(releaseUuid, tenantId);
|
|
|
|
return null;
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
|
|
|
|
String msg = "Couldn't found an application release for application release UUID: " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lifecycleState.setNextStates(new ArrayList<>(lifecycleStateManager.getNextLifecycleStates(lifecycleState.getCurrentState())));
|
|
|
|
return this.lifecycleStateDAO.getLifecycleStates(applicationReleaseDTO.getId(), tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
throw new ApplicationManagementException("Failed to get lifecycle state from database", e);
|
|
|
|
String msg = "Failed to get lifecycle state for application release uuid " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error occurred while getting application release for application release UUID: " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lifecycleState;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void changeLifecycleState(int applicationId, String releaseUuid, LifecycleStateDTO state)
|
|
|
|
public void changeLifecycleState(String releaseUuid, String stateName)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
if (!this.applicationDAO.verifyApplicationExistenceById(applicationId, tenantId)) {
|
|
|
|
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
|
|
|
|
throw new NotFoundException("Couldn't find application for the application Id: " + applicationId);
|
|
|
|
.getReleaseByUUID(releaseUuid, tenantId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.applicationReleaseDAO.verifyReleaseExistence(applicationId, releaseUuid, tenantId)) {
|
|
|
|
if (applicationReleaseDTO == null) {
|
|
|
|
throw new NotFoundException("Couldn't find application release for the application Id: " + applicationId
|
|
|
|
String msg = "Couldn't found an application release for the UUID: " + releaseUuid;
|
|
|
|
+ " application release uuid: " + releaseUuid);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new NotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LifecycleStateDTO currentState = this.lifecycleStateDAO.getLatestLifeCycleState(applicationId, releaseUuid);
|
|
|
|
|
|
|
|
if (currentState == null) {
|
|
|
|
if (lifecycleStateManager
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
.isValidStateChange(applicationReleaseDTO.getCurrentState(), stateName, userName, tenantId)) {
|
|
|
|
"Couldn't find latest lifecycle state for the appId: " + applicationId
|
|
|
|
if (lifecycleStateManager.isInstallableState(stateName) && applicationReleaseDAO
|
|
|
|
+ " and application release UUID: " + releaseUuid);
|
|
|
|
.hasExistInstallableAppRelease(applicationReleaseDTO.getUuid(),
|
|
|
|
|
|
|
|
lifecycleStateManager.getInstallableState(), tenantId)) {
|
|
|
|
|
|
|
|
String msg = "Installable application release is already registered for the application. "
|
|
|
|
|
|
|
|
+ "Therefore it is not permitted to change the lifecycle state from "
|
|
|
|
|
|
|
|
+ applicationReleaseDTO.getCurrentState() + " to " + stateName;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ForbiddenException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
state.setPreviousState(currentState.getCurrentState());
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
lifecycleState.setCurrentState(stateName);
|
|
|
|
state.setUpdatedBy(userName);
|
|
|
|
lifecycleState.setPreviousState(applicationReleaseDTO.getCurrentState());
|
|
|
|
|
|
|
|
lifecycleState.setUpdatedBy(userName);
|
|
|
|
if (state.getCurrentState() != null && state.getPreviousState() != null) {
|
|
|
|
applicationReleaseDTO.setCurrentState(stateName);
|
|
|
|
if (lifecycleStateManager.isValidStateChange(state.getPreviousState(), state.getCurrentState(),
|
|
|
|
this.applicationReleaseDAO.updateRelease(applicationReleaseDTO, tenantId);
|
|
|
|
userName, tenantId)) {
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
|
|
|
|
//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)
|
|
|
|
|
|
|
|
this.lifecycleStateDAO.addLifecycleState(state, applicationId, releaseUuid, tenantId);
|
|
|
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'"
|
|
|
|
log.error("Invalid lifecycle state transition from '" + state.getPreviousState() + "'" + " to '"
|
|
|
|
+ " to '" + stateName + "'";
|
|
|
|
+ state.getCurrentState() + "'");
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
"Lifecycle State Validation failed. ApplicationDTO Id: " + applicationId
|
|
|
|
|
|
|
|
+ " ApplicationDTO release UUID: " + releaseUuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
} catch (LifeCycleManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
String msg = "Failed to add lifecycle state for Application release UUID: " + releaseUuid;
|
|
|
|
"Failed to add lifecycle state. ApplicationDTO Id: " + applicationId + " ApplicationDTO release UUID: "
|
|
|
|
log.error(msg);
|
|
|
|
+ releaseUuid, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
//todo
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
throw new ApplicationManagementException("");
|
|
|
|
String msg = "Error occurred when accessing application release data of application release which has the "
|
|
|
|
|
|
|
|
+ "application release UUID: " + releaseUuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1898,11 +1910,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|
|
|
* By invoking the method, it returns Lifecycle State Instance.
|
|
|
|
* By invoking the method, it returns Lifecycle State Instance.
|
|
|
|
* @param currentState Current state of the lifecycle
|
|
|
|
* @param currentState Current state of the lifecycle
|
|
|
|
* @param previousState Previouse state of the Lifecycle
|
|
|
|
* @param previousState Previouse state of the Lifecycle
|
|
|
|
* @return {@link LifecycleStateDTO}
|
|
|
|
* @return {@link LifecycleState}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private LifecycleStateDTO getLifecycleStateInstance(String currentState, String previousState) {
|
|
|
|
private LifecycleState getLifecycleStateInstance(String currentState, String previousState) {
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
LifecycleStateDTO lifecycleState = new LifecycleStateDTO();
|
|
|
|
LifecycleState lifecycleState = new LifecycleState();
|
|
|
|
lifecycleState.setCurrentState(currentState);
|
|
|
|
lifecycleState.setCurrentState(currentState);
|
|
|
|
lifecycleState.setPreviousState(previousState);
|
|
|
|
lifecycleState.setPreviousState(previousState);
|
|
|
|
lifecycleState.setUpdatedBy(userName);
|
|
|
|
lifecycleState.setUpdatedBy(userName);
|
|
|
|