use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class NetworkACLManagerImpl method replaceNetworkACL.
@Override
public boolean replaceNetworkACL(final NetworkACL acl, final NetworkVO network) throws ResourceUnavailableException {
final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
if (guestNtwkOff == null) {
throw new InvalidParameterValueException("Can't find network offering associated with network: " + network.getUuid());
}
// verify that ACLProvider is supported by network offering
if (!_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL)) {
throw new InvalidParameterValueException("Cannot apply NetworkACL. Network Offering does not support NetworkACL service");
}
if (network.getNetworkACLId() != null) {
// Revoke ACL Items of the existing ACL if the new ACL is empty
// Existing rules won't be removed otherwise
final List<NetworkACLItemVO> aclItems = _networkACLItemDao.listByACL(acl.getId());
if (aclItems == null || aclItems.isEmpty()) {
s_logger.debug("New network ACL is empty. Revoke existing rules before applying ACL");
if (!revokeACLItemsForNetwork(network.getId())) {
throw new CloudRuntimeException("Failed to replace network ACL. Error while removing existing ACL items for network: " + network.getId());
}
}
}
network.setNetworkACLId(acl.getId());
// Update Network ACL
if (_networkDao.update(network.getId(), network)) {
s_logger.debug("Updated network: " + network.getId() + " with Network ACL Id: " + acl.getId() + ", Applying ACL items");
// Apply ACL to network
final Boolean result = applyACLToNetwork(network.getId());
if (result) {
// public message on message bus, so that network elements implementing distributed routing capability
// can act on the event
_messageBus.publish(_name, "Network_ACL_Replaced", PublishScope.LOCAL, network);
}
return result;
}
return false;
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class ArrayTypeAdaptor method deserialize.
@Override
public T[] deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
final JsonArray array = json.getAsJsonArray();
final Iterator<JsonElement> it = array.iterator();
final ArrayList<T> cmds = new ArrayList<>();
while (it.hasNext()) {
final JsonObject element = (JsonObject) it.next();
final Map.Entry<String, JsonElement> entry = element.entrySet().iterator().next();
final String name = entry.getKey();
final Class<?> clazz;
try {
clazz = Class.forName(name);
} catch (final ClassNotFoundException e) {
throw new CloudRuntimeException("can't find " + name);
}
final T cmd = (T) _gson.fromJson(entry.getValue(), clazz);
cmds.add(cmd);
}
final Class<?> type;
final String typeOfTClass = typeOfT.getTypeName().replace("[]", "");
try {
type = Class.forName(typeOfTClass);
} catch (ClassNotFoundException e) {
throw new CloudRuntimeException("can't find " + typeOfTClass);
}
final T[] ts = (T[]) Array.newInstance(type, cmds.size());
return cmds.toArray(ts);
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class InterfaceTypeAdaptor method deserialize.
@Override
public T deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
final JsonObject element = (JsonObject) json;
final Map.Entry<String, JsonElement> entry = element.entrySet().iterator().next();
final String name = entry.getKey();
final Class<?> clazz;
try {
clazz = Class.forName(name);
} catch (final ClassNotFoundException e) {
throw new CloudRuntimeException("can't find " + name);
}
return (T) _gson.fromJson(entry.getValue(), clazz);
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCopyVolumeCommandCloudRuntime2.
@Test
public void testCopyVolumeCommandCloudRuntime2() {
final StoragePool storagePool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long volumeId = 1l;
final int wait = 0;
final String volumePath = "/vol/path";
final boolean toSecondaryStorage = false;
final boolean executeInSequence = false;
final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
final StorageFilerTO pool = command.getPool();
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenThrow(new CloudRuntimeException("error"));
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.
the class AddNetworkDeviceCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
final Host device = nwDeviceMgr.addNetworkDevice(this);
final NetworkDeviceResponse response = nwDeviceMgr.getApiResponse(device);
response.setObjectName("networkdevice");
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (final InvalidParameterValueException ipve) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage());
} catch (final CloudRuntimeException cre) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage());
}
}
Aggregations