Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2A2B010E29 for ; Wed, 27 Nov 2013 10:19:08 +0000 (UTC) Received: (qmail 7042 invoked by uid 500); 27 Nov 2013 10:19:07 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 6897 invoked by uid 500); 27 Nov 2013 10:19:05 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 6877 invoked by uid 99); 27 Nov 2013 10:19:03 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Nov 2013 10:19:03 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 24D2D91993B; Wed, 27 Nov 2013 10:18:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dahn@apache.org To: commits@cloudstack.apache.org Message-Id: <757bb7c0ba784f669c67995e4367841b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/master to 2774b62 Date: Wed, 27 Nov 2013 10:18:56 +0000 (UTC) Updated Branches: refs/heads/master c781e3b66 -> 2774b62d6 Fixing bugs from Coverity related to Dereferenced Null after check and as return value. Signed-off-by: Daan Hoogland Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2774b62d Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2774b62d Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2774b62d Branch: refs/heads/master Commit: 2774b62d64989bddc1e4664ef7a93dff11c77657 Parents: c781e3b Author: wilderrodrigues Authored: Fri Nov 8 15:18:05 2013 +0100 Committer: Daan Hoogland Committed: Wed Nov 27 11:18:00 2013 +0100 ---------------------------------------------------------------------- agent/src/com/cloud/agent/AgentShell.java | 14 +- .../contrail/management/ServiceManagerImpl.java | 16 +- .../contrail/model/VirtualMachineModel.java | 68 ++++---- .../api/command/LdapImportUsersCmd.java | 37 ++--- .../cloud/server/ConfigurationServerImpl.java | 159 ++++++++++--------- utils/src/com/cloud/utils/nio/Link.java | 9 +- 6 files changed, 160 insertions(+), 143 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2774b62d/agent/src/com/cloud/agent/AgentShell.java ---------------------------------------------------------------------- diff --git a/agent/src/com/cloud/agent/AgentShell.java b/agent/src/com/cloud/agent/AgentShell.java index 936e3cd..87004f9 100644 --- a/agent/src/com/cloud/agent/AgentShell.java +++ b/agent/src/com/cloud/agent/AgentShell.java @@ -167,7 +167,8 @@ public class AgentShell implements IAgentShell, Daemon { void loadProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("agent.properties"); - if (file == null) { + + if (null == file) { throw new ConfigurationException("Unable to find agent.properties."); } @@ -303,12 +304,17 @@ public class AgentShell implements IAgentShell, Daemon { // For KVM agent, do it specially here File file = new File("/etc/cloudstack/agent/log4j-cloud.xml"); - if (!file.exists()) { + if(!file.exists()) { file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); } - DOMConfigurator.configureAndWatch(file.getAbsolutePath()); - s_logger.info("Agent started"); + if (null != file) { + DOMConfigurator.configureAndWatch(file.getAbsolutePath()); + + s_logger.info("Agent started"); + } else { + s_logger.error("Could not start the Agent because the absolut path of the \"log4j-cloud.xml\" file cannot be determined."); + } final Class c = this.getClass(); _version = c.getPackage().getImplementationVersion(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2774b62d/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java index ca44757..e15e2ce 100644 --- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java +++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java @@ -29,14 +29,11 @@ import net.juniper.contrail.api.ApiConnector; import net.juniper.contrail.api.types.ServiceInstance; import net.juniper.contrail.api.types.VirtualNetwork; -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.network.contrail.api.response.ServiceInstanceResponse; import org.apache.cloudstack.network.contrail.model.ServiceInstanceModel; import org.apache.cloudstack.network.contrail.model.VirtualMachineModel; +import org.apache.log4j.Logger; import com.cloud.api.ApiDBUtils; import com.cloud.dc.DataCenter; @@ -61,6 +58,7 @@ import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.VirtualMachineName; import com.cloud.vm.dao.UserVmDao; +import com.google.gson.Gson; @Local(value = {ServiceManager.class}) public class ServiceManagerImpl implements ServiceManager { @@ -98,7 +96,7 @@ public class ServiceManagerImpl implements ServiceManager { */ @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "createServiceInstance", create = true) private ServiceVirtualMachine createServiceVM(DataCenter zone, Account owner, VirtualMachineTemplate template, ServiceOffering serviceOffering, String name, - ServiceInstance siObj, Network left, Network right) { + ServiceInstance siObj, Network left, Network right) { long id = _vmDao.getNextInSequence(Long.class, "id"); DataCenterDeployment plan = new DataCenterDeployment(zone.getId()); @@ -111,8 +109,8 @@ public class ServiceManagerImpl implements ServiceManager { String instanceName = VirtualMachineName.getVmName(id, owner.getId(), "SRV"); ServiceVirtualMachine svm = - new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(), - zone.getId(), owner.getDomainId(), owner.getAccountId(), false); + new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(), + zone.getId(), owner.getDomainId(), owner.getAccountId(), false); // database synchronization code must be able to distinguish service instance VMs. Map kvmap = new HashMap(); @@ -132,7 +130,7 @@ public class ServiceManagerImpl implements ServiceManager { @Override public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owner, VirtualMachineTemplate template, ServiceOffering serviceOffering, String name, - Network left, Network right) { + Network left, Network right) { s_logger.debug("createServiceInstance by " + owner.getAccountName()); // TODO: permission model. // service instances need to be able to access the public network. @@ -227,10 +225,12 @@ public class ServiceManagerImpl implements ServiceManager { @Override public ServiceInstanceResponse createServiceInstanceResponse(long instanceId) { s_logger.debug("ServiceInstance response for id: " + instanceId); + UserVmVO vm = _vmDao.findById(instanceId); ServiceInstanceResponse response = new ServiceInstanceResponse(); response.setId(vm.getUuid()); Account owner = _accountService.getAccount(vm.getAccountId()); + if (owner.getType() == Account.ACCOUNT_TYPE_PROJECT) { Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(owner.getAccountId()); response.setProjectId(project.getUuid()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2774b62d/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java index 32d5d93..96cea95 100644 --- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java +++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java @@ -27,12 +27,8 @@ import net.juniper.contrail.api.types.Project; import net.juniper.contrail.api.types.ServiceInstance; import net.juniper.contrail.api.types.VirtualMachine; -import org.apache.log4j.Logger; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; - import org.apache.cloudstack.network.contrail.management.ContrailManager; +import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.network.dao.NetworkDao; @@ -42,11 +38,13 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.NicVO; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.dao.NicDao; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; public class VirtualMachineModel extends ModelObjectBase { private static final Logger s_logger = Logger.getLogger(VirtualMachineModel.class); - private String _uuid; + private final String _uuid; private long _instanceId; /* @@ -113,8 +111,12 @@ public class VirtualMachineModel extends ModelObjectBase { throw new CloudRuntimeException("Unable to read service-instance object", ex); } if (siObj == null) { + //If the ServiceInstance object is null, do not call build. It will break in many places. Instead, call update passing the controller as parameter. + //It will then create a new ServiceInstance is that's null. siModel = new ServiceInstanceModel(serviceUuid); - siModel.build(controller, siObj); + siModel.update(controller); + + siObj = siModel.getServiceInstance(); } } _serviceModel = siModel; @@ -197,21 +199,21 @@ public class VirtualMachineModel extends ModelObjectBase { boolean isActiveInstance(VMInstanceVO instance) { switch (instance.getState()) { - case Migrating: - case Starting: - case Running: - case Shutdowned: - case Stopped: - case Stopping: - return true; - - case Destroyed: - case Error: - case Expunging: - return false; - - default: - s_logger.warn("Unknown VMInstance state " + instance.getState().getDescription()); + case Migrating: + case Starting: + case Running: + case Shutdowned: + case Stopped: + case Stopping: + return true; + + case Destroyed: + case Error: + case Expunging: + return false; + + default: + s_logger.warn("Unknown VMInstance state " + instance.getState().getDescription()); } return true; } @@ -255,17 +257,17 @@ public class VirtualMachineModel extends ModelObjectBase { String tag; switch (nic.getDeviceId()) { - case 0: - tag = "management"; - break; - case 1: - tag = "left"; - break; - case 2: - tag = "right"; - break; - default: - tag = null; + case 0: + tag = "management"; + break; + case 1: + tag = "left"; + break; + case 2: + tag = "right"; + break; + default: + tag = null; } VMInterfaceModel vmiModel = getVMInterface(nic.getUuid()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2774b62d/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java ---------------------------------------------------------------------- diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java index 129392e..d817c33 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java @@ -25,10 +25,6 @@ import java.util.UUID; import javax.inject.Inject; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.bouncycastle.util.encoders.Base64; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -41,6 +37,9 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.ldap.LdapManager; import org.apache.cloudstack.ldap.LdapUser; import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.bouncycastle.util.encoders.Base64; import com.cloud.domain.Domain; import com.cloud.exception.ConcurrentOperationException; @@ -60,29 +59,29 @@ public class LdapImportUsersCmd extends BaseListCmd { private static final String s_name = "ldapuserresponse"; @Parameter(name = ApiConstants.TIMEZONE, - type = CommandType.STRING, - description = "Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.") + type = CommandType.STRING, + description = "Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.") private String timezone; @Parameter(name = ApiConstants.ACCOUNT_TYPE, - type = CommandType.SHORT, - required = true, - description = "Type of the account. Specify 0 for user, 1 for root admin, and 2 for domain admin") + type = CommandType.SHORT, + required = true, + description = "Type of the account. Specify 0 for user, 1 for root admin, and 2 for domain admin") private Short accountType; @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters") private Map details; @Parameter(name = ApiConstants.DOMAIN_ID, - type = CommandType.UUID, - entityType = DomainResponse.class, - description = "Specifies the domain to which the ldap users are to be " - + "imported. If no domain is specified, a domain will created using group parameter. If the group is also not specified, a domain name based on the OU information will be " - + "created. If no OU hierarchy exists, will be defaulted to ROOT domain") + type = CommandType.UUID, + entityType = DomainResponse.class, + description = "Specifies the domain to which the ldap users are to be " + + "imported. If no domain is specified, a domain will created using group parameter. If the group is also not specified, a domain name based on the OU information will be " + + "created. If no OU hierarchy exists, will be defaulted to ROOT domain") private Long domainId; @Parameter(name = ApiConstants.GROUP, type = CommandType.STRING, description = "Specifies the group name from which the ldap users are to be imported. " - + "If no group is specified, all the users will be imported.") + + "If no group is specified, all the users will be imported.") private String groupName; private Domain _domain; @@ -103,11 +102,12 @@ public class LdapImportUsersCmd extends BaseListCmd { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, - ResourceAllocationException, NetworkRuleConflictException { + ResourceAllocationException, NetworkRuleConflictException { List users; try { if (StringUtils.isNotBlank(groupName)) { + users = _ldapManager.getUsersInGroup(groupName); } else { users = _ldapManager.getUsers(); @@ -122,7 +122,7 @@ public class LdapImportUsersCmd extends BaseListCmd { Domain domain = getDomain(user); try { _accountService.createUserAccount(user.getUsername(), generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone, - user.getUsername(), accountType, domain.getId(), domain.getNetworkDomain(), details, UUID.randomUUID().toString(), UUID.randomUUID().toString()); + user.getUsername(), accountType, domain.getId(), domain.getNetworkDomain(), details, UUID.randomUUID().toString(), UUID.randomUUID().toString()); addedUsers.add(user); } catch (InvalidParameterValueException ex) { s_logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage()); @@ -194,7 +194,8 @@ public class LdapImportUsersCmd extends BaseListCmd { final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG"); final byte bytes[] = new byte[20]; randomGen.nextBytes(bytes); - return Base64.encode(bytes).toString(); + String encodedPassword = new String(Base64.encode(bytes)); + return encodedPassword; } catch (final NoSuchAlgorithmException e) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate random password"); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2774b62d/server/src/com/cloud/server/ConfigurationServerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index cfc95ca..f907831 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -42,15 +42,14 @@ import javax.crypto.SecretKey; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; - import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigDepotAdmin; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.impl.ConfigurationVO; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.FileUtils; +import org.apache.log4j.Logger; import com.cloud.cluster.ClusterManager; import com.cloud.configuration.Config; @@ -158,7 +157,6 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio @Override public boolean configure(String name, Map params) throws ConfigurationException { - try { persistDefaultValues(); _configDepotAdmin.populateConfigurations(); @@ -285,7 +283,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio long startIPLong = NetUtils.ip2Long(startIp); long endIPLong = NetUtils.ip2Long(endIp); config.savePublicIPRange(TransactionLegacy.currentTxn(), startIPLong, endIPLong, vlan.getDataCenterId(), vlan.getId(), vlan.getNetworkId(), - vlan.getPhysicalNetworkId()); + vlan.getPhysicalNetworkId()); } }); @@ -372,16 +370,16 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio if (resouce == null) continue; if (resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56Resource") || - resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56FP1Resource") || - resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56SP2Resource") || - resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer600Resource") || - resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer602Resource")) { + resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56FP1Resource") || + resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer56SP2Resource") || + resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer600Resource") || + resouce.equalsIgnoreCase("com.cloud.hypervisor.xen.resource.XenServer602Resource")) { pvdriverversion = "xenserver56"; break; } } _configDao.getValueAndInitIfNotExist(Config.XenPVdriverVersion.key(), Config.XenPVdriverVersion.getCategory(), pvdriverversion, - Config.XenPVdriverVersion.getDescription()); + Config.XenPVdriverVersion.getDescription()); sql = "select id from vm_template where hypervisor_type='XenServer' and format!='ISO' and removed is null"; pstmt = txn.prepareAutoCloseStatement(sql); rs2 = pstmt.executeQuery(); @@ -421,7 +419,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio _identityDao.initializeDefaultUuid("user_ip_address"); _identityDao.initializeDefaultUuid("counter"); } - */ + */ private String getMountParent() { return getEnvironmentProperty("mount.parent"); @@ -457,8 +455,8 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio } // insert system user insertSql = - "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, user.default)" - + " VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), 1)"; + "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, user.default)" + + " VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), 1)"; txn = TransactionLegacy.currentTxn(); try { PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); @@ -475,7 +473,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio // create an account for the admin user first insertSql = - "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, account.default) VALUES (" + id + ", UUID(), '" + username + "', '1', '1', 1)"; + "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, account.default) VALUES (" + id + ", UUID(), '" + username + "', '1', '1', 1)"; txn = TransactionLegacy.currentTxn(); try { PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql); @@ -485,7 +483,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio // now insert the user insertSql = - "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, state, user.default) " + "VALUES (" + id + + "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, state, user.default) " + "VALUES (" + id + ", UUID(), '" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled', 1)"; txn = TransactionLegacy.currentTxn(); @@ -513,11 +511,11 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio // save default security group if (tableName.equals("security_group")) { insertSql = - "INSERT INTO " + tableName + " (uuid, name, description, account_id, domain_id) " + "VALUES (UUID(), 'default', 'Default Security Group', 2, 1)"; + "INSERT INTO " + tableName + " (uuid, name, description, account_id, domain_id) " + "VALUES (UUID(), 'default', 'Default Security Group', 2, 1)"; } else { insertSql = - "INSERT INTO " + tableName + " (name, description, account_id, domain_id, account_name) " + - "VALUES ('default', 'Default Security Group', 2, 1, 'admin')"; + "INSERT INTO " + tableName + " (name, description, account_id, domain_id, account_name) " + + "VALUES ('default', 'Default Security Group', 2, 1, 'admin')"; } txn = TransactionLegacy.currentTxn(); @@ -597,27 +595,34 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio } String dbString = _configDao.getValue("ssl.keystore"); + File confFile = PropertiesUtil.findConfigFile("db.properties"); - /* This line may throw a NPE, but that's due to fail to find db.properities, meant some bugs in the other places */ - String confPath = confFile.getParent(); - String keystorePath = confPath + "/cloudmanagementserver.keystore"; - File keystoreFile = new File(keystorePath); + String confPath = null; + String keystorePath = null; + File keystoreFile = null; + + if (null != confFile) { + confPath = confFile.getParent(); + keystorePath = confPath + "/cloud.keystore"; + keystoreFile = new File(keystorePath); + } + boolean dbExisted = (dbString != null && !dbString.isEmpty()); s_logger.info("SSL keystore located at " + keystorePath); try { - if (!dbExisted) { + if (!dbExisted && null != confFile) { if (!keystoreFile.exists()) { generateDefaultKeystore(keystorePath); s_logger.info("Generated SSL keystore."); } String base64Keystore = getBase64Keystore(keystorePath); ConfigurationVO configVO = - new ConfigurationVO("Hidden", "DEFAULT", "management-server", "ssl.keystore", DBEncryptionUtil.encrypt(base64Keystore), - "SSL Keystore for the management servers"); + new ConfigurationVO("Hidden", "DEFAULT", "management-server", "ssl.keystore", DBEncryptionUtil.encrypt(base64Keystore), + "SSL Keystore for the management servers"); _configDao.persist(configVO); s_logger.info("Stored SSL keystore to database."); - } else if (keystoreFile.exists()) { // and dbExisted + } else if (null != keystoreFile && keystoreFile.exists()) { // and dbExisted // Check if they are the same one, otherwise override with local keystore String base64Keystore = getBase64Keystore(keystorePath); if (base64Keystore.compareTo(dbString) != 0) { @@ -634,7 +639,11 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio fo.close(); Script script = new Script(true, "cp", 5000, null); script.add(tmpKeystorePath); - script.add(keystorePath); + + //There is a chance, although small, that the keystorePath is null. In that case, do not add it to the script. + if (null != keystorePath) { + script.add(keystorePath); + } String result = script.execute(); if (result != null) { throw new IOException(); @@ -666,9 +675,9 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio try { String rpassword = PasswordGenerator.generatePresharedKey(8); String wSql = - "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + - "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', '" + DBEncryptionUtil.encrypt(rpassword) + - "','randmon password generated each management server starts for system vm')"; + "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', '" + DBEncryptionUtil.encrypt(rpassword) + + "','randmon password generated each management server starts for system vm')"; PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.executeUpdate(wSql); s_logger.info("Updated systemvm password in database"); @@ -743,13 +752,13 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio String publicKey = new String(arr2).trim(); String insertSql1 = - "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + - "VALUES ('Hidden','DEFAULT', 'management-server','ssh.privatekey', '" + DBEncryptionUtil.encrypt(privateKey) + - "','Private key for the entire CloudStack')"; + "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + + "VALUES ('Hidden','DEFAULT', 'management-server','ssh.privatekey', '" + DBEncryptionUtil.encrypt(privateKey) + + "','Private key for the entire CloudStack')"; String insertSql2 = - "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + - "VALUES ('Hidden','DEFAULT', 'management-server','ssh.publickey', '" + DBEncryptionUtil.encrypt(publicKey) + - "','Public key for the entire CloudStack')"; + "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + + "VALUES ('Hidden','DEFAULT', 'management-server','ssh.publickey', '" + DBEncryptionUtil.encrypt(publicKey) + + "','Public key for the entire CloudStack')"; TransactionLegacy txn = TransactionLegacy.currentTxn(); try { @@ -882,9 +891,9 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio String password = PasswordGenerator.generateRandomPassword(12); String insertSql1 = - "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + - "VALUES ('Hidden','DEFAULT', 'management-server','secstorage.copy.password', '" + DBEncryptionUtil.encrypt(password) + - "','Password used to authenticate zone-to-zone template copy requests')"; + "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + + "VALUES ('Hidden','DEFAULT', 'management-server','secstorage.copy.password', '" + DBEncryptionUtil.encrypt(password) + + "','Password used to authenticate zone-to-zone template copy requests')"; TransactionLegacy txn = TransactionLegacy.currentTxn(); try { @@ -915,7 +924,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio @DB protected HostPodVO createPod(long userId, String podName, final long zoneId, String gateway, String cidr, final String startIp, String endIp) - throws InternalErrorException { + throws InternalErrorException { String[] cidrPair = cidr.split("\\/"); String cidrAddress = cidrPair[0]; int cidrSize = Integer.parseInt(cidrPair[1]); @@ -974,7 +983,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio } private DiskOfferingVO createdefaultDiskOffering(Long domainId, String name, String description, int numGibibytes, String tags, boolean isCustomized, - boolean isSystemUse) { + boolean isSystemUse) { long diskSize = numGibibytes; diskSize = diskSize * 1024 * 1024 * 1024; tags = cleanupTags(tags); @@ -987,10 +996,10 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio } private ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, - boolean offerHA, String tags) { + boolean offerHA, String tags) { tags = cleanupTags(tags); ServiceOfferingVO offering = - new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, displayText, localStorageRequired, false, tags, false, null, false); + new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, displayText, localStorageRequired, false, tags, false, null, false); offering.setUniqueName("Cloud.Com-" + name); offering = _serviceOfferingDao.persistSystemServiceOffering(offering); return offering; @@ -1065,87 +1074,87 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio public void doInTransactionWithoutResult(TransactionStatus status) { // Offering #1 NetworkOfferingVO defaultSharedSGNetworkOffering = - new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", - TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false); + new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", + TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false); defaultSharedSGNetworkOffering.setState(NetworkOffering.State.Enabled); defaultSharedSGNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedSGNetworkOffering); for (Service service : defaultSharedSGNetworkOfferingProviders.keySet()) { NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultSharedSGNetworkOffering.getId(), service, defaultSharedSGNetworkOfferingProviders.get(service)); + new NetworkOfferingServiceMapVO(defaultSharedSGNetworkOffering.getId(), service, defaultSharedSGNetworkOfferingProviders.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } // Offering #2 NetworkOfferingVO defaultSharedNetworkOffering = - new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, false, true, null, null, true, - Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false); + new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, false, true, null, null, true, + Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false); defaultSharedNetworkOffering.setState(NetworkOffering.State.Enabled); defaultSharedNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedNetworkOffering); for (Service service : defaultSharedNetworkOfferingProviders.keySet()) { NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultSharedNetworkOffering.getId(), service, defaultSharedNetworkOfferingProviders.get(service)); + new NetworkOfferingServiceMapVO(defaultSharedNetworkOffering.getId(), service, defaultSharedNetworkOfferingProviders.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } // Offering #3 NetworkOfferingVO defaultIsolatedSourceNatEnabledNetworkOffering = - new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, - "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Required, null, - Network.GuestType.Isolated, true, false, false, false, true); + new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, + "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Required, null, + Network.GuestType.Isolated, true, false, false, false, true); defaultIsolatedSourceNatEnabledNetworkOffering.setState(NetworkOffering.State.Enabled); defaultIsolatedSourceNatEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedSourceNatEnabledNetworkOffering); for (Service service : defaultIsolatedSourceNatEnabledNetworkOfferingProviders.keySet()) { NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service, - defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service)); + new NetworkOfferingServiceMapVO(defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service, + defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } // Offering #4 NetworkOfferingVO defaultIsolatedEnabledNetworkOffering = - new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, - false, true, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, true, true, false, false, false); + new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, + false, true, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, true, true, false, false, false); defaultIsolatedEnabledNetworkOffering.setState(NetworkOffering.State.Enabled); defaultIsolatedEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedEnabledNetworkOffering); for (Service service : defaultIsolatedNetworkOfferingProviders.keySet()) { NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultIsolatedEnabledNetworkOffering.getId(), service, defaultIsolatedNetworkOfferingProviders.get(service)); + new NetworkOfferingServiceMapVO(defaultIsolatedEnabledNetworkOffering.getId(), service, defaultIsolatedNetworkOfferingProviders.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } // Offering #5 NetworkOfferingVO defaultNetscalerNetworkOffering = - new NetworkOfferingVO(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, - "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, false, true, null, null, true, - Availability.Optional, null, Network.GuestType.Shared, true, false, false, false, true, true, true, false, false, true, true, false, false); + new NetworkOfferingVO(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, + "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, false, true, null, null, true, + Availability.Optional, null, Network.GuestType.Shared, true, false, false, false, true, true, true, false, false, true, true, false, false); defaultNetscalerNetworkOffering.setState(NetworkOffering.State.Enabled); defaultNetscalerNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetscalerNetworkOffering); for (Service service : netscalerServiceProviders.keySet()) { NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultNetscalerNetworkOffering.getId(), service, netscalerServiceProviders.get(service)); + new NetworkOfferingServiceMapVO(defaultNetscalerNetworkOffering.getId(), service, netscalerServiceProviders.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } // Offering #6 NetworkOfferingVO defaultNetworkOfferingForVpcNetworks = - new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, - "Offering for Isolated Vpc networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Optional, - null, Network.GuestType.Isolated, false, false, false, false, true); + new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, + "Offering for Isolated Vpc networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Optional, + null, Network.GuestType.Isolated, false, false, false, false, true); defaultNetworkOfferingForVpcNetworks.setState(NetworkOffering.State.Enabled); defaultNetworkOfferingForVpcNetworks = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworks); @@ -1164,16 +1173,16 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio for (Service service : defaultVpcNetworkOfferingProviders.keySet()) { NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworks.getId(), service, defaultVpcNetworkOfferingProviders.get(service)); + new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworks.getId(), service, defaultVpcNetworkOfferingProviders.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } // Offering #7 NetworkOfferingVO defaultNetworkOfferingForVpcNetworksNoLB = - new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB, - "Offering for Isolated Vpc networks with Source Nat service enabled and LB service Disabled", TrafficType.Guest, false, false, null, null, true, - Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false); + new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB, + "Offering for Isolated Vpc networks with Source Nat service enabled and LB service Disabled", TrafficType.Guest, false, false, null, null, true, + Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false); defaultNetworkOfferingForVpcNetworksNoLB.setState(NetworkOffering.State.Enabled); defaultNetworkOfferingForVpcNetworksNoLB = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworksNoLB); @@ -1191,16 +1200,16 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio for (Service service : defaultVpcNetworkOfferingProvidersNoLB.keySet()) { NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworksNoLB.getId(), service, defaultVpcNetworkOfferingProvidersNoLB.get(service)); + new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworksNoLB.getId(), service, defaultVpcNetworkOfferingProvidersNoLB.get(service)); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } //offering #8 - network offering with internal lb service NetworkOfferingVO internalLbOff = - new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, - "Offering for Isolated Vpc networks with Internal LB support", TrafficType.Guest, false, false, null, null, true, Availability.Optional, null, - Network.GuestType.Isolated, false, false, false, true, false); + new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, + "Offering for Isolated Vpc networks with Internal LB support", TrafficType.Guest, false, false, null, null, true, Availability.Optional, null, + Network.GuestType.Isolated, false, false, false, true, false); internalLbOff.setState(NetworkOffering.State.Enabled); internalLbOff = _networkOfferingDao.persistDefaultNetworkOffering(internalLbOff); @@ -1275,8 +1284,8 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio if (broadcastDomainType != null) { NetworkVO network = - new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, - Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null); + new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, + Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null); network.setGuruName(guruNames.get(network.getTrafficType())); network.setDns1(zone.getDns1()); network.setDns2(zone.getDns2()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2774b62d/utils/src/com/cloud/utils/nio/Link.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/nio/Link.java b/utils/src/com/cloud/utils/nio/Link.java index 3b30053..e20210d 100755 --- a/utils/src/com/cloud/utils/nio/Link.java +++ b/utils/src/com/cloud/utils/nio/Link.java @@ -150,7 +150,7 @@ public class Link { pkgBuf.clear(); engResult = sslEngine.wrap(buffers, pkgBuf); if (engResult.getHandshakeStatus() != HandshakeStatus.FINISHED && engResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && - engResult.getStatus() != SSLEngineResult.Status.OK) { + engResult.getStatus() != SSLEngineResult.Status.OK) { throw new IOException("SSL: SSLEngine return bad result! " + engResult); } @@ -276,7 +276,7 @@ public class Link { appBuf = ByteBuffer.allocate(sslSession.getApplicationBufferSize() + 40); engResult = _sslEngine.unwrap(_readBuffer, appBuf); if (engResult.getHandshakeStatus() != HandshakeStatus.FINISHED && engResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && - engResult.getStatus() != SSLEngineResult.Status.OK) { + engResult.getStatus() != SSLEngineResult.Status.OK) { throw new IOException("SSL: SSLEngine return bad result! " + engResult); } if (remaining == _readBuffer.remaining()) { @@ -404,10 +404,9 @@ public class Link { KeyStore ks = KeyStore.getInstance("JKS"); TrustManager[] tms; - if (!isClient) { + File confFile = PropertiesUtil.findConfigFile("db.properties"); + if (null != confFile && !isClient) { char[] passphrase = "vmops.com".toCharArray(); - File confFile = PropertiesUtil.findConfigFile("db.properties"); - /* This line may throw a NPE, but that's due to fail to find db.properities, meant some bugs in the other places */ String confPath = confFile.getParent(); String keystorePath = confPath + "/cloud.keystore"; if (new File(keystorePath).exists()) {