Updated Branches: refs/heads/master 52e6ef7eb -> 11971b5a5
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11971b5a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java index cea3ac2..afc402e 100755 --- a/utils/src/com/cloud/utils/exception/CloudRuntimeException.java +++ b/utils/src/com/cloud/utils/exception/CloudRuntimeException.java @@ -29,11 +29,11 @@ public class CloudRuntimeException extends RuntimeException implements ErrorCont private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException; - protected ArrayList<Pair<Class<?>, String>> uuidList = new ArrayList<Pair<Class<?>, String>>(); - // This holds a list of uuids and their descriptive names. protected ArrayList<ExceptionProxyObject> idList = new ArrayList<ExceptionProxyObject>(); + protected ArrayList<Pair<Class<?>, String>> uuidList = new ArrayList<Pair<Class<?>, String>>(); + protected int csErrorCode; @@ -47,7 +47,7 @@ public class CloudRuntimeException extends RuntimeException implements ErrorCont setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); } - public CloudRuntimeException() { + protected CloudRuntimeException() { super(); setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); } @@ -65,6 +65,12 @@ public class CloudRuntimeException extends RuntimeException implements ErrorCont idList.add(proxy); } + @Override + public CloudRuntimeException add(Class<?> entity, String uuid) { + uuidList.add(new Pair<Class<?>, String>(entity, uuid)); + return this; + } + public ArrayList<ExceptionProxyObject> getIdProxyList() { return idList; } @@ -78,13 +84,7 @@ public class CloudRuntimeException extends RuntimeException implements ErrorCont } public CloudRuntimeException(Throwable t) { - super(t); - } - - @Override - public CloudRuntimeException add(Class<?> entity, String uuid) { - uuidList.add(new Pair<Class<?>, String>(entity, uuid)); - return this; + super(t.getMessage(), t); } @Override http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11971b5a/utils/src/org/apache/cloudstack/config/ConfigDepot.java ---------------------------------------------------------------------- diff --git a/utils/src/org/apache/cloudstack/config/ConfigDepot.java b/utils/src/org/apache/cloudstack/config/ConfigDepot.java new file mode 100644 index 0000000..f2f0bad --- /dev/null +++ b/utils/src/org/apache/cloudstack/config/ConfigDepot.java @@ -0,0 +1,25 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.config; + +/** + * ConfigDepot is a repository of configurations. + * + */ +public interface ConfigDepot { + <T> ConfigValue<T> get(ConfigKey<T> key); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11971b5a/utils/src/org/apache/cloudstack/config/ConfigKey.java ---------------------------------------------------------------------- diff --git a/utils/src/org/apache/cloudstack/config/ConfigKey.java b/utils/src/org/apache/cloudstack/config/ConfigKey.java new file mode 100644 index 0000000..9e42831 --- /dev/null +++ b/utils/src/org/apache/cloudstack/config/ConfigKey.java @@ -0,0 +1,98 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.config; + +/** + * ConfigKey supplants the original Config.java. It is just a class + * declaration where others can declare their config variables. + * + * TODO: This class should be moved to a framework project where the gathering + * of these configuration keys should be done by a config server. I + * don't have time yet to do this. Ask me about it if you want to work + * in this area. Right now, we'll just work with the actual names. + */ +public class ConfigKey<T> { + + private final String _category; + + public String category() { + return _category; + } + + public Class<?> component() { + return _componentClass; + } + + public Class<T> type() { + return _type; + } + + public String key() { + return _name; + } + + public String defaultValue() { + return _defaultValue; + } + + public String description() { + return _description; + } + + public String range() { + return _range; + } + + public String scope() { + return _scope; + } + + public boolean isDynamic() { + return _isDynamic; + } + + @Override + public String toString() { + return _name; + } + + private final Class<?> _componentClass; + private final Class<T> _type; + private final String _name; + private final String _defaultValue; + private final String _description; + private final String _range; + private final String _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global + private final boolean _isDynamic; + + public ConfigKey(Class<T> type, String name, String category, Class<?> componentClass, String defaultValue, String description, boolean isDynamic, String range, + String scope) { + _category = category; + _componentClass = componentClass; + _type = type; + _name = name; + _defaultValue = defaultValue; + _description = description; + _range = range; + _scope = scope; + _isDynamic = isDynamic; + } + + public ConfigKey(Class<T> type, String name, String category, Class<?> componentClass, String defaultValue, String description, boolean isDynamic, String range) { + this(type, name, category, componentClass, defaultValue, description, isDynamic, range, null); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11971b5a/utils/src/org/apache/cloudstack/config/ConfigValue.java ---------------------------------------------------------------------- diff --git a/utils/src/org/apache/cloudstack/config/ConfigValue.java b/utils/src/org/apache/cloudstack/config/ConfigValue.java new file mode 100644 index 0000000..013b835 --- /dev/null +++ b/utils/src/org/apache/cloudstack/config/ConfigValue.java @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.config; + +import com.cloud.utils.db.EntityManager; +import com.cloud.utils.exception.CloudRuntimeException; + +/** + * This is a match set to ConfigKey. + * + * TODO: When we create a framework project for configuration, this should be + * moved there. + */ +public class ConfigValue<T> { + + ConfigKey<T> _config; + EntityManager _entityMgr; + Number _multiplier; + T _value; + + public ConfigValue(EntityManager entityMgr, ConfigKey<T> config) { + _entityMgr = entityMgr; + _config = config; + _multiplier = 1; + } + + public ConfigKey<T> getConfigKey() { + return _config; + } + + public ConfigValue<T> setMultiplier(Number multiplier) { // Convience method + _multiplier = multiplier; + return this; + } + + @SuppressWarnings("unchecked") + public T value() { + if (_value == null || _config.isDynamic()) { + Configuration vo = _entityMgr.findById(Configuration.class, _config.key()); + String value = vo != null ? vo.getValue() : _config.defaultValue(); + + Class<T> type = _config.type(); + if (type.isAssignableFrom(Boolean.class)) { + _value = (T)Boolean.valueOf(value); + } else if (type.isAssignableFrom(Integer.class)) { + _value = (T)new Integer((Integer.parseInt(value) * _multiplier.intValue())); + } else if (type.isAssignableFrom(Long.class)) { + _value = (T)new Long(Long.parseLong(value) * _multiplier.longValue()); + } else if (type.isAssignableFrom(Short.class)) { + _value = (T)new Short(Short.parseShort(value)); + } else if (type.isAssignableFrom(String.class)) { + _value = (T)value; + } else if (type.isAssignableFrom(Float.class)) { + _value = (T)new Float(Float.parseFloat(value) * _multiplier.floatValue()); + } else { + throw new CloudRuntimeException("Unsupported data type for config values: " + type); + } + } + + return _value; + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11971b5a/utils/src/org/apache/cloudstack/config/Configuration.java ---------------------------------------------------------------------- diff --git a/utils/src/org/apache/cloudstack/config/Configuration.java b/utils/src/org/apache/cloudstack/config/Configuration.java new file mode 100644 index 0000000..8657832 --- /dev/null +++ b/utils/src/org/apache/cloudstack/config/Configuration.java @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.config; + +public interface Configuration { + + public String getCategory(); + + public String getInstance(); + + public String getComponent(); + + public String getName(); + + public String getValue(); + + public String getDescription(); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11971b5a/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java b/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java index fc54dfb..220bd80 100644 --- a/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java +++ b/utils/src/org/apache/cloudstack/test/utils/SpringUtils.java @@ -47,7 +47,7 @@ public class SpringUtils { * useDefaultFilters=true. See the following example. * * <pre> - * @ComponentScan(basePackageClasses={AffinityGroupServiceImpl.class, ActionEventUtils.class}, + * @ComponentScan(basePackageClasses={AffinityGroupServiceImpl.class, EventUtils.class}, * includeFilters={@Filter(value=TestConfiguration.Library.class, type=FilterType.CUSTOM)}, * useDefaultFilters=false) * </pre> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/11971b5a/utils/src/org/apache/cloudstack/utils/identity/ManagementServerNode.java ---------------------------------------------------------------------- diff --git a/utils/src/org/apache/cloudstack/utils/identity/ManagementServerNode.java b/utils/src/org/apache/cloudstack/utils/identity/ManagementServerNode.java new file mode 100755 index 0000000..5135bcd --- /dev/null +++ b/utils/src/org/apache/cloudstack/utils/identity/ManagementServerNode.java @@ -0,0 +1,60 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.utils.identity; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.ComponentLifecycle; +import com.cloud.utils.component.SystemIntegrityChecker; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.net.MacAddress; + +@Local(value = {SystemIntegrityChecker.class}) +public class ManagementServerNode extends AdapterBase implements SystemIntegrityChecker { + private final Logger s_logger = Logger.getLogger(ManagementServerNode.class); + + private static final long s_nodeId = MacAddress.getMacAddress().toLong(); + + public ManagementServerNode() { + setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK_BOOTSTRAP); + } + + @Override + public void check() { + if (s_nodeId <= 0) { + throw new CloudRuntimeException("Unable to get the management server node id"); + } + } + + public static long getManagementServerId() { + return s_nodeId; + } + + @Override + public boolean start() { + try { + check(); + } catch (Exception e) { + s_logger.error("System integrity check exception", e); + System.exit(1); + } + return true; + } +}