use of com.cloud.api.response.NetworkACLItemResponse in project cosmic by MissionCriticalCloud.
the class UpdateNetworkACLItemCmd method execute.
@Override
public void execute() throws ResourceUnavailableException {
CallContext.current().setEventDetails("Rule Id: " + getId());
final NetworkACLItem aclItem = _networkACLService.updateNetworkACLItem(getId(), getProtocol(), getSourceCidrList(), getTrafficType(), getAction(), getNumber(), getSourcePortStart(), getSourcePortEnd(), getIcmpCode(), getIcmpType(), this.getCustomId(), this.isDisplay());
if (aclItem == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network ACL item");
}
final NetworkACLItemResponse aclResponse = _responseGenerator.createNetworkACLItemResponse(aclItem);
setResponseObject(aclResponse);
aclResponse.setResponseName(getCommandName());
}
use of com.cloud.api.response.NetworkACLItemResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createNetworkACLItemResponse.
@Override
public NetworkACLItemResponse createNetworkACLItemResponse(final NetworkACLItem aclItem) {
final NetworkACLItemResponse response = new NetworkACLItemResponse();
response.setId(aclItem.getUuid());
response.setProtocol(aclItem.getProtocol());
if (aclItem.getSourcePortStart() != null) {
response.setStartPort(Integer.toString(aclItem.getSourcePortStart()));
}
if (aclItem.getSourcePortEnd() != null) {
response.setEndPort(Integer.toString(aclItem.getSourcePortEnd()));
}
response.setCidrList(StringUtils.join(aclItem.getSourceCidrList(), ","));
response.setTrafficType(aclItem.getTrafficType().toString());
final NetworkACLItem.State state = aclItem.getState();
String stateToSet = state.toString();
if (state.equals(NetworkACLItem.State.Revoke)) {
stateToSet = "Deleting";
}
response.setIcmpCode(aclItem.getIcmpCode());
response.setIcmpType(aclItem.getIcmpType());
response.setState(stateToSet);
response.setNumber(aclItem.getNumber());
response.setAction(aclItem.getAction().toString());
response.setForDisplay(aclItem.isDisplay());
final NetworkACL acl = ApiDBUtils.findByNetworkACLId(aclItem.getAclId());
if (acl != null) {
response.setAclId(acl.getUuid());
}
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.NetworkACL, aclItem.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("networkacl");
return response;
}
use of com.cloud.api.response.NetworkACLItemResponse in project cosmic by MissionCriticalCloud.
the class ApiSerializerHelperTest method testFromSerializedStringOtherSuccessResponse.
@Test
public void testFromSerializedStringOtherSuccessResponse() {
final String string = "com.cloud.api.response.NetworkACLItemResponse/networkacl/{\"id\":\"00000000-0000-0000-0000-000000000000\",\"protocol\":\"tcp\"," + "\"startport\":\"22\",\"endport\":\"22\",\"traffictype\":\"Ingress\",\"state\":\"Active\",\"cidrlist\":\"10.1.0.0/16,10.2.0.0/16\"," + "\"tags\":[],\"aclid\":\"00000000-0000-0000-0000-000000000000\",\"number\":1,\"action\":\"Allow\",\"fordisplay\":true}";
final Object object = ApiSerializerHelper.fromSerializedString(string);
assertNotNull(object);
assertEquals(NetworkACLItemResponse.class, object.getClass());
final NetworkACLItemResponse response = (NetworkACLItemResponse) object;
assertEquals("networkacl", response.getObjectName());
assertEquals(string, ApiSerializerHelper.toSerializedString(response));
}
use of com.cloud.api.response.NetworkACLItemResponse in project cosmic by MissionCriticalCloud.
the class ListNetworkACLsCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
final Pair<List<? extends NetworkACLItem>, Integer> result = _networkACLService.listNetworkACLItems(this);
final ListResponse<NetworkACLItemResponse> response = new ListResponse<>();
final List<NetworkACLItemResponse> aclResponses = new ArrayList<>();
for (final NetworkACLItem acl : result.first()) {
final NetworkACLItemResponse ruleData = _responseGenerator.createNetworkACLItemResponse(acl);
aclResponses.add(ruleData);
}
response.setResponses(aclResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.api.response.NetworkACLItemResponse in project cosmic by MissionCriticalCloud.
the class CreateNetworkACLCmd method execute.
@Override
public void execute() throws ResourceUnavailableException {
boolean success = false;
NetworkACLItem rule = _networkACLService.getNetworkACLItem(getEntityId());
try {
CallContext.current().setEventDetails("Rule ID: " + getEntityId());
success = _networkACLService.applyNetworkACL(rule.getAclId());
// State is different after the rule is applied, so get new object here
rule = _networkACLService.getNetworkACLItem(getEntityId());
NetworkACLItemResponse aclResponse = new NetworkACLItemResponse();
if (rule != null) {
aclResponse = _responseGenerator.createNetworkACLItemResponse(rule);
setResponseObject(aclResponse);
}
aclResponse.setResponseName(getCommandName());
} finally {
if (!success || rule == null) {
_networkACLService.revokeNetworkACLItem(getEntityId());
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network ACL Item");
}
}
}
Aggregations