Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This PR...
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] build/CI

### Feature/Enhancement Scale or Bug Severity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ConfigKey(Class<T> type, String name, String category, String defaultValu

public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier,
String displayText, String parent, Ternary<String, String, Long> group, Pair<String, Long> subGroup) {
this(type, name, category, defaultValue, description, isDynamic, scope, multiplier, null, parent, null, null, null, null);
this(type, name, category, defaultValue, description, isDynamic, scope, multiplier, displayText, parent, group, subGroup, null, null);
}

public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ public void testAutoPopulation() {
ConfigurationVO staticIntCV = new ConfigurationVO("UnitTestComponent", StaticIntCK);
dynamicIntCV.setValue("200");
ConfigurationVO testCV = new ConfigurationVO("UnitTestComponent", TestCK);
ConfigurationGroupVO groupVO = new ConfigurationGroupVO();
ConfigurationSubGroupVO subGroupVO = new ConfigurationSubGroupVO();

when(_configurable.getConfigComponentName()).thenReturn("UnitTestComponent");
when(_configurable.getConfigKeys()).thenReturn(new ConfigKey<?>[] {DynamicIntCK, StaticIntCK, TestCK});
when(_configDao.findById(StaticIntCK.key())).thenReturn(null);
when(_configDao.findById(DynamicIntCK.key())).thenReturn(dynamicIntCV);
when(_configDao.findById(TestCK.key())).thenReturn(testCV);
when(_configDao.persist(any(ConfigurationVO.class))).thenReturn(dynamicIntCV);
when(_configGroupDao.persist(any(ConfigurationGroupVO.class))).thenReturn(groupVO);
when(_configSubGroupDao.persist(any(ConfigurationSubGroupVO.class))).thenReturn(subGroupVO);
_depotAdmin.populateConfigurations();

// This is once because DynamicIntCK is returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public <T> SearchBuilder<T> createSearchBuilder(Class<T> entityType) {

public <T, K> GenericSearchBuilder<T, K> createGenericSearchBuilder(Class<T> entityType, Class<K> resultType) {
GenericDao<T, ? extends Serializable> dao = (GenericDao<T, ? extends Serializable>)GenericDaoBase.getDao(entityType);
return dao.createSearchBuilder((Class<K>)resultType.getClass());
return dao.createSearchBuilder((Class<K>)resultType);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions framework/db/src/main/java/com/cloud/utils/db/DbUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static PrimaryKeyJoinColumn[] getPrimaryKeyJoinColumns(Class<?> clazz) {
public static Field findField(Class<?> clazz, String columnName) {
for (Field field : clazz.getDeclaredFields()) {
if (field.getAnnotation(Embedded.class) != null || field.getAnnotation(EmbeddedId.class) != null) {
findField(field.getClass(), columnName);
findField(field.getType(), columnName);
} else {
if (columnName.equals(DbUtil.getColumnName(field))) {
return field;
Expand Down Expand Up @@ -170,7 +170,7 @@ public static final boolean isIdField(Field field) {
}

if (field.getAnnotation(EmbeddedId.class) != null) {
assert (field.getClass().getAnnotation(Embeddable.class) != null) : "Class " + field.getClass().getName() + " must be Embeddable to be used as Embedded Id";
assert (field.getType().getAnnotation(Embeddable.class) != null) : "Class " + field.getType().getName() + " must be Embeddable to be used as Embedded Id";
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// under the License.
package com.cloud.utils.db;

import java.lang.reflect.InvocationTargetException;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -56,12 +58,13 @@ public static void loadDriver(String dbDriver) {
}

try {
Class.forName(driverClass).newInstance();
Class<Driver> klazz = (Class<Driver>) Class.forName(driverClass);
klazz.getDeclaredConstructor().newInstance();
LOADED_DRIVERS.add(dbDriver);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Successfully loaded DB driver " + driverClass);
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error("Failed to load DB driver " + driverClass);
throw new CloudRuntimeException("Failed to load DB driver " + driverClass, e);
}
Expand Down
4 changes: 2 additions & 2 deletions framework/db/src/main/java/com/cloud/utils/db/EcInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public EcInfo(Attribute attr, Attribute idAttr) {
rawClass = HashSet.class;
} else if (List.class == rawClazz) {
rawClass = ArrayList.class;
} else if (Collection.class == Collection.class) {
} else if (Collection.class == rawClazz) {
rawClass = ArrayList.class;
} else {
assert (false) : " We don't know how to create this calss " + rawType.toString() + " for " + attr.field.getName();
assert (false) : " We don't know how to create this class " + rawType.toString() + " for " + attr.field.getName();
}
} catch (NoSuchMethodException e) {
throw new CloudRuntimeException("Write your own support for " + rawClazz + " defined by " + attr.field.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,8 @@ protected String buildSelectByIdSql(final StringBuilder sql) {
if (_idField.getAnnotation(EmbeddedId.class) == null) {
sql.append(_table).append(".").append(DbUtil.getColumnName(_idField, null)).append(" = ? ");
} else {
final Class<?> clazz = _idField.getClass();
s_logger.debug(String.format("field type vs declarator : %s vs %s", _idField.getType(), _idField.getDeclaringClass()));
final Class<?> clazz = _idField.getType();
final AttributeOverride[] overrides = DbUtil.getAttributeOverrides(_idField);
for (final Field field : clazz.getDeclaredFields()) {
sql.append(_table).append(".").append(DbUtil.getColumnName(field, overrides)).append(" = ? AND ");
Expand Down
2 changes: 1 addition & 1 deletion utils/src/main/java/com/cloud/utils/SerialVersionUID.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* purposes. This is purely on an honor system though. You should always
**/
public interface SerialVersionUID {
public static final long Base = 0x564D4F70 << 32; // 100 brownie points if you guess what this is and tell me.
public static final long Base = 0x564D4F70L << 32; // 100 brownie points if you guess what this is and tell me.

public static final long UUID = Base | 0x1;
public static final long CloudRuntimeException = Base | 0x2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -160,5 +161,10 @@ public boolean equals(Object o) {
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(this.clazz, this.subscriber, this.methodName, this.method);
}
}
}
1 change: 1 addition & 0 deletions utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ public void testIsIpv4ExpectException2() {
NetUtils.isIpv4("2001:db8:300::/64");
}

@Test
public void testAllIpsOfDefaultNic() {
final String defaultHostIp = NetUtils.getDefaultHostIp();
if (defaultHostIp != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ public void validateAddressAndPrepareForUrlTestIpv6() {
public void buildRequestUrlTestHttpsGetSystemId() {
RedfishClient redfishclient = new RedfishClient(USERNAME, PASSWORD, true, false, REDFISHT_REQUEST_RETRIES);
String result = redfishclient.buildRequestUrl(oobAddress, RedfishClient.RedfishCmdType.GetSystemId, systemId);
String expected = String.format("https://%s/redfish/v1/Systems/", oobAddress, systemId);
Comment thread
DaanHoogland marked this conversation as resolved.
String expected = String.format("https://%s/redfish/v1/Systems/", oobAddress);
Comment thread
DaanHoogland marked this conversation as resolved.
Assert.assertEquals(expected, result);
}

@Test
public void buildRequestUrlTestGetSystemId() {
RedfishClient redfishclient = new RedfishClient(USERNAME, PASSWORD, false, false, REDFISHT_REQUEST_RETRIES);
String result = redfishclient.buildRequestUrl(oobAddress, RedfishClient.RedfishCmdType.GetSystemId, systemId);
String expected = String.format("http://%s/redfish/v1/Systems/", oobAddress, systemId);
String expected = String.format("http://%s/redfish/v1/Systems/", oobAddress);
Comment thread
DaanHoogland marked this conversation as resolved.
Assert.assertEquals(expected, result);
}

Expand Down