Fixing minor issues in PlatformDeployment

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

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

@ -24,7 +24,9 @@ import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; 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.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.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
@ -66,9 +68,18 @@ public class PlatformDeployer extends AbstractDeployer {
Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile); Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile);
if (platformConf.getId().contentEquals(getPlatformID(deploymentFile.getName()))) { if (platformConf.getId().contentEquals(getPlatformID(deploymentFile.getName()))) {
org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf); org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf);
DataHolder.getInstance().getPlatformManager() PlatformManager platformManager = DataHolder.getInstance().getPlatformManager();
.register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform); int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
log.info("Platform configuration : " + deploymentFile.getName() + " deployed successfully");
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 { } else {
log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath() log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath()
+ "!. Platform config file name - " + deploymentFile.getName() + "!. Platform config file name - " + deploymentFile.getName()
@ -89,7 +100,7 @@ public class PlatformDeployer extends AbstractDeployer {
.unregister(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platformId, true); .unregister(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platformId, true);
log.info("Platform configuration : " + fileName + " un-deployed successfully"); log.info("Platform configuration : " + fileName + " un-deployed successfully");
} catch (PlatformManagementException e) { } 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() "Platform sharing is a restricted operation, therefore Platform - " + platform.getIdentifier()
+ " cannot be shared by the tenant domain - " + tenantId); + " 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)) { if (oldPlatform == null) {
try { ConnectionManagerUtil.rollbackTransaction();
ConnectionManagerUtil.openConnection(); 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()); Platform existingPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, platform.getIdentifier());
if (existingPlatform != null) { if (existingPlatform != null) {
ConnectionManagerUtil.rollbackTransaction();
throw new PlatformManagementException( throw new PlatformManagementException(
"Cannot update the identifier of the platform from '" + oldPlatformIdentifier + "' to '" "Cannot update the identifier of the platform from '" + oldPlatformIdentifier + "' to '"
+ platform.getIdentifier() + "'. Another platform exists " + platform.getIdentifier() + "'. Another platform exists "
+ "already with the identifier '" + platform.getIdentifier() + "' for the tenant : " + "already with the identifier '" + platform.getIdentifier() + "' for the tenant : "
+ tenantId); + 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()) { if (platform.isFileBased()) {
Map<String, Platform> tenantPlatforms = this.inMemoryStore.get(tenantId); 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) { if (tenantPlatforms == null) {
throw new PlatformManagementException( tenantPlatforms = new HashMap<>();
"No platforms registered for the tenant - " + tenantId + " with platform identifier - " this.inMemoryStore.put(tenantId, tenantPlatforms);
+ platform.getIdentifier());
} }
oldPlatform = tenantPlatforms.get(oldPlatformIdentifier); if (tenantPlatforms.get(platform.getIdentifier()) == null) {
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());
tenantPlatforms.put(platform.getIdentifier(), platform); tenantPlatforms.put(platform.getIdentifier(), platform);
} }
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
platform.setId(oldPlatform.getId());
tenantPlatforms.put(platform.getIdentifier(), platform);
} else { } else {
ConnectionManagerUtil.beginTransaction();
oldPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, oldPlatformIdentifier);
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform); DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
} }
if (platform.isDefaultTenantMapping() && !oldPlatform.isDefaultTenantMapping()) { if (platform.isDefaultTenantMapping() && !oldPlatform.isDefaultTenantMapping()) {
@ -292,6 +288,7 @@ public class PlatformManagerImpl implements PlatformManager {
} }
DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier())); DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier()));
} catch (UserStoreException e) { } catch (UserStoreException e) {
ConnectionManagerUtil.rollbackTransaction();
throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!", throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!",
e); e);
} }

Loading…
Cancel
Save