Improve lifecycle management

merge-requests/7/head
lasanthaDLPDS 6 years ago
parent 34fe427852
commit 3e2f757c1e

@ -19,28 +19,41 @@
package org.wso2.carbon.device.application.mgt.common;
import java.sql.Timestamp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@ApiModel(value = "LifecycleState", description = "LifecycleState represents the an Lifecycle state for an application release")
public class LifecycleState {
@ApiModelProperty(name = "id",
value = "ID of the application release lifecycle",
required = true)
private int id;
@ApiModelProperty(name = "currentState",
value = "Current state of the application release",
required = true)
private String currentState;
@ApiModelProperty(name = "previousState",
value = "Previous state of the application release",
required = true)
private String previousState;
@ApiModelProperty(name = "nextStates",
value = "Next possible transferring states from the current state")
private List<String> nextStates;
@ApiModelProperty(name = "updatedBy",
value = "Username who is update the application release state")
private String updatedBy;
@ApiModelProperty(name = "updatedAt",
value = "Timestamp of the lifecycle has been updated")
private Timestamp updatedAt;
private int tenantId;
private int releaseId;
private int appId;
public int getId() {
return id;
}
@ -81,30 +94,6 @@ public class LifecycleState {
this.updatedAt = updatedAt;
}
public int getTenantId() {
return tenantId;
}
public void setTenantId(int tenantId) {
this.tenantId = tenantId;
}
public int getReleaseId() {
return releaseId;
}
public void setReleaseId(int releaseId) {
this.releaseId = releaseId;
}
public int getAppId() {
return appId;
}
public void setAppId(int appId) {
this.appId = appId;
}
public List<String> getNextStates() {
return nextStates;
}

@ -33,7 +33,7 @@ public interface LifecycleStateDAO {
List<LifecycleState> getLifecycleStates(int appReleaseId) throws LifeCycleManagementDAOException;
void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException;
void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException;
void deleteLifecycleState(int identifier) throws LifeCycleManagementDAOException;

@ -92,7 +92,6 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
lifecycleState.setId(rs.getInt("ID"));
lifecycleState.setCurrentState(rs.getString("CURRENT_STATE"));
lifecycleState.setPreviousState(rs.getString("PREVIOUSE_STATE"));
lifecycleState.setTenantId(rs.getInt("TENANT_ID"));
lifecycleState.setUpdatedAt(rs.getTimestamp("UPDATED_AT"));
lifecycleState.setUpdatedBy(rs.getString("UPDATED_BY"));
lifecycleStates.add(lifecycleState);
@ -109,7 +108,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
}
@Override
public void addLifecycleState(LifecycleState state) throws LifeCycleManagementDAOException {
public void addLifecycleState(LifecycleState state, int appId, int releaseId, int tenantId) throws LifeCycleManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
try {
@ -119,10 +118,10 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
stmt = conn.prepareStatement(sql);
stmt.setString(1, state.getCurrentState());
stmt.setString(2, state.getPreviousState());
stmt.setInt(3, state.getTenantId());
stmt.setInt(3, tenantId);
stmt.setString(4, state.getUpdatedBy());
stmt.setInt(5, state.getReleaseId());
stmt.setInt(6, state.getAppId());
stmt.setInt(5, releaseId);
stmt.setInt(6, appId);
stmt.executeUpdate();
} catch (DBConnectionException e) {

@ -126,21 +126,23 @@ public class ApplicationManagerImpl implements ApplicationManager {
"Invalid payload. Application creating payload should contains one application release, but "
+ "the payload contains more than one");
}
ConnectionManagerUtil.commitDBTransaction();
applicationRelease = application.getApplicationReleases().get(0);
applicationRelease = ApplicationManagementDAOFactory.getApplicationReleaseDAO().
createRelease(applicationRelease, application.getId(), tenantId);
LifecycleState lifecycleState = new LifecycleState();
lifecycleState.setAppId(application.getId());
lifecycleState.setReleaseId(applicationRelease.getId());
lifecycleState.setUpdatedBy(userName);
lifecycleState.setTenantId(tenantId);
lifecycleState.setCurrentState(AppLifecycleState.CREATED.toString());
lifecycleState.setPreviousState(AppLifecycleState.CREATED.toString());
addLifecycleState(application.getId(), applicationRelease.getUuid(), lifecycleState);
LifecycleStateDAO lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStateDAO.addLifecycleState(lifecycleState, application.getId(), applicationRelease.getId(), tenantId);
applicationRelease.setLifecycleState(lifecycleState);
applicationReleases.add(applicationRelease);
application.setApplicationReleases(applicationReleases);
ConnectionManagerUtil.commitDBTransaction();
}
return application;
@ -155,7 +157,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg, e);
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException(msg, e);
} finally {
} catch (LifeCycleManagementDAOException e) {
String msg = "Error occurred while adding application lifecycle state";
log.error(msg, e);
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException(msg, e);
}finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@ -399,7 +406,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
LifecycleState newAppLifecycleState = new LifecycleState();
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
storedLocations.add(applicationRelease.getAppHashValue());
@ -437,7 +443,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
LifecycleState newAppLifecycleState = new LifecycleState();
newAppLifecycleState.setPreviousState(appLifecycleState.getCurrentState());
newAppLifecycleState.setCurrentState(AppLifecycleState.REMOVED.toString());
newAppLifecycleState.setTenantId(tenantId);
newAppLifecycleState.setUpdatedBy(userName);
addLifecycleState(applicationId, applicationRelease.getUuid(), newAppLifecycleState);
}else{
@ -710,17 +715,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
Application application = validateApplication(applicationId);
ApplicationRelease applicationRelease = validateApplicationRelease(applicationId, applicationUuid);
LifecycleStateDAO lifecycleStateDAO;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (application != null) {
state.setAppId(applicationId);
}
if (applicationRelease != null) {
state.setReleaseId(applicationRelease.getId());
}
if (state.getCurrentState() != null && state.getPreviousState() != null && state.getUpdatedBy() != null) {
validateLifecycleState(state);
lifecycleStateDAO = ApplicationManagementDAOFactory.getLifecycleStateDAO();
lifecycleStateDAO.addLifecycleState(state);
lifecycleStateDAO.addLifecycleState(state, application.getId(), applicationRelease.getId(), tenantId);
}
} catch (LifeCycleManagementDAOException | DBConnectionException e) {
throw new ApplicationManagementException("Failed to add lifecycle state", e);

Loading…
Cancel
Save