Fixing minor issues in PlatformDeployment

feature/appm-store/pbac
megala21 8 years ago
parent eda5b5909c
commit 7d191d63c5

@ -171,10 +171,11 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
preparedStatement.execute();
}
}
} else {
} else if (!isIdentifierNull) {
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ? WHERE ID = ?";
preparedStatement = connection.prepareStatement(insertToPlatform);
preparedStatement.setInt(1, platformId);
preparedStatement.setString(1, platform.getIdentifier());
preparedStatement.setInt(2, platformId);
preparedStatement.execute();
}
} else {

@ -24,7 +24,9 @@ import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
@ -66,9 +68,18 @@ public class PlatformDeployer extends AbstractDeployer {
Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile);
if (platformConf.getId().contentEquals(getPlatformID(deploymentFile.getName()))) {
org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf);
DataHolder.getInstance().getPlatformManager()
.register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform);
log.info("Platform configuration : " + deploymentFile.getName() + " deployed successfully");
PlatformManager platformManager = DataHolder.getInstance().getPlatformManager();
int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
org.wso2.carbon.device.application.mgt.common.Platform existingPlatform = platformManager
.getPlatform(tenantID, platform.getIdentifier());
if (existingPlatform != null && existingPlatform.isFileBased()) {
platformManager.update(tenantID, platformConf.getId(),platform);
log.info("Platform configuration : " + deploymentFile.getName() + " updated successfully");
} else {
platformManager.register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform);
log.info("Platform configuration : " + deploymentFile.getName() + " deployed successfully");
}
} else {
log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath()
+ "!. Platform config file name - " + deploymentFile.getName()
@ -89,7 +100,7 @@ public class PlatformDeployer extends AbstractDeployer {
.unregister(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platformId, true);
log.info("Platform configuration : " + fileName + " un-deployed successfully");
} catch (PlatformManagementException e) {
log.error("Error occurred while un-deploying the platform - " + fileName);
log.error("Error occurred while un-deploying the platform - " + fileName, e);
}
}

@ -233,50 +233,46 @@ public class PlatformManagerImpl implements PlatformManager {
"Platform sharing is a restricted operation, therefore Platform - " + platform.getIdentifier()
+ " cannot be shared by the tenant domain - " + tenantId);
}
Platform oldPlatform;
try {
ConnectionManagerUtil.beginTransaction();
Platform oldPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, oldPlatformIdentifier);
if (platform.getIdentifier() != null && !platform.getIdentifier().equals(oldPlatformIdentifier)) {
try {
ConnectionManagerUtil.openConnection();
if (oldPlatform == null) {
ConnectionManagerUtil.rollbackTransaction();
throw new PlatformManagementException(
"Cannot update platform. Platform with identifier : " + oldPlatformIdentifier
+ " does not exist.");
}
if (platform.getIdentifier() != null && !platform.getIdentifier().equals(oldPlatformIdentifier)) {
Platform existingPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, platform.getIdentifier());
if (existingPlatform != null) {
ConnectionManagerUtil.rollbackTransaction();
throw new PlatformManagementException(
"Cannot update the identifier of the platform from '" + oldPlatformIdentifier + "' to '"
+ platform.getIdentifier() + "'. Another platform exists "
+ "already with the identifier '" + platform.getIdentifier() + "' for the tenant : "
+ tenantId);
}
} catch (DBConnectionException e) {
throw new PlatformManagementException(
"Database Connection Exception while trying to update the " + "platform for the tenant : "
+ tenantId, e);
} finally {
ConnectionManagerUtil.closeConnection();
}
}
try {
if (platform.isFileBased()) {
Map<String, Platform> tenantPlatforms = this.inMemoryStore.get(tenantId);
// File based configurations will be updated in the server start-up as well.So in that case, cache,
// will be empty.
if (tenantPlatforms == null) {
throw new PlatformManagementException(
"No platforms registered for the tenant - " + tenantId + " with platform identifier - "
+ platform.getIdentifier());
tenantPlatforms = new HashMap<>();
this.inMemoryStore.put(tenantId, tenantPlatforms);
}
oldPlatform = tenantPlatforms.get(oldPlatformIdentifier);
if (oldPlatform == null) {
throw new PlatformManagementException(
"No platforms registered for the tenant - " + tenantId + " with platform identifier - "
+ platform.getIdentifier());
} else {
ConnectionManagerUtil.beginTransaction();
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
platform.setId(oldPlatform.getId());
if (tenantPlatforms.get(platform.getIdentifier()) == null) {
tenantPlatforms.put(platform.getIdentifier(), platform);
}
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
platform.setId(oldPlatform.getId());
tenantPlatforms.put(platform.getIdentifier(), platform);
} else {
ConnectionManagerUtil.beginTransaction();
oldPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, oldPlatformIdentifier);
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
}
if (platform.isDefaultTenantMapping() && !oldPlatform.isDefaultTenantMapping()) {
@ -292,6 +288,7 @@ public class PlatformManagerImpl implements PlatformManager {
}
DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier()));
} catch (UserStoreException e) {
ConnectionManagerUtil.rollbackTransaction();
throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!",
e);
}

Loading…
Cancel
Save