Package com.cloud.utils.exception

Examples of com.cloud.utils.exception.ExecutionException


          if (!unitNum.equals("0")) {
            vlanTag = Long.parseLong(unitNum);
          }
        } catch (Exception e) {
          s_logger.error(e);
          throw new ExecutionException("Unable to parse VLAN tag from interface name: " + interfaceName);
        }
      }
   
      return vlanTag;
    }
View Full Code Here


            xml = SrxXml.PROXY_ARP_ADD.getXml();
            xml = replaceXmlValue(xml, "public-interface-name", publicInterface);
            xml = replaceXmlValue(xml, "public-ip-address", publicIp);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add proxy ARP entry for public IP " + publicIp);
            } else {
                return true;
            }

        case DELETE:
            if (!manageProxyArp(SrxCommand.CHECK_IF_EXISTS, publicVlanTag, publicIp)) {
                return true;
            }

            if (manageProxyArp(SrxCommand.CHECK_IF_IN_USE, publicVlanTag, publicIp)) {
                return true;
            }

            xml = SrxXml.PROXY_ARP_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "public-interface-name", publicInterface);
            xml = replaceXmlValue(xml, "public-ip-address", publicIp);

            if (!sendRequestAndCheckResponse(command, xml, "name", publicIp)) {
                throw new ExecutionException("Failed to delete proxy ARP entry for public IP " + publicIp);
            } else {
                return true;
            }

        default:
View Full Code Here

            xml = SrxXml.ZONE_INTERFACE_ADD.getXml();
            xml = replaceXmlValue(xml, "private-zone-name", _privateZone);
            xml = replaceXmlValue(xml, "zone-interface-name", zoneInterfaceName);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add interface " + zoneInterfaceName + " to zone " + _privateZone);
            } else {
                return true;
            }

        case DELETE:
            if (!manageZoneInterface(SrxCommand.CHECK_IF_EXISTS, vlanTag)) {
                return true;
            }

            xml = SrxXml.ZONE_INTERFACE_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "private-zone-name", _privateZone);
            xml = replaceXmlValue(xml, "zone-interface-name", zoneInterfaceName);

            if (!sendRequestAndCheckResponse(command, xml, "name", zoneInterfaceName)) {
                throw new ExecutionException("Failed to delete interface " + zoneInterfaceName + " from zone " + _privateZone);
            } else {
                return true;
            }

        default:
View Full Code Here

            xml = replaceXmlValue(xml, "rule-name", ruleName);
            xml = replaceXmlValue(xml, "original-ip", publicIp);
            xml = replaceXmlValue(xml, "translated-ip", privateIp);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add static NAT rule from public IP " + publicIp + " to private IP " + privateIp);
            } else {
                return true;
            }

        case DELETE:
            if (!manageStaticNatRule(SrxCommand.CHECK_IF_EXISTS, publicIp, privateIp)) {
                return true;
            }

            xml = SrxXml.STATIC_NAT_RULE_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "rule-set", _publicZone);
            xml = replaceXmlValue(xml, "from-zone", _publicZone);
            xml = replaceXmlValue(xml, "rule-name", ruleName);

            if (!sendRequestAndCheckResponse(command, xml, "name", ruleName)) {
                throw new ExecutionException("Failed to delete static NAT rule from public IP " + publicIp + " to private IP " + privateIp);
            } else {
                return true;
            }

        default:
            throw new ExecutionException("Unrecognized command.");

        }
    }
View Full Code Here

            xml = replaceXmlValue(xml, "pool-name", poolName);
            xml = replaceXmlValue(xml, "private-address", privateIp + "/32");
            xml = replaceXmlValue(xml, "dest-port", String.valueOf(destPort));

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add destination NAT pool for private IP " + privateIp + " and private port " + destPort);
            } else {
                return true;
            }

        case DELETE:
            if (!manageDestinationNatPool(SrxCommand.CHECK_IF_EXISTS, privateIp, destPort)) {
                return true;
            }

            if (manageDestinationNatPool(SrxCommand.CHECK_IF_IN_USE, privateIp, destPort)) {
                return true;
            }

            xml = SrxXml.DEST_NAT_POOL_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "pool-name", poolName);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to delete destination NAT pool for private IP " + privateIp + " and private port " + destPort);
            } else {
                return true;
            }

        default:
            throw new ExecutionException("Unrecognized command.");
        }
    }
View Full Code Here

            if (manageDestinationNatRule(SrxCommand.CHECK_IF_EXISTS, publicIp, privateIp, srcPort, destPort)) {
                return true;
            }

            if (!manageDestinationNatPool(SrxCommand.CHECK_IF_EXISTS, privateIp, destPort)) {
                throw new ExecutionException("The destination NAT pool corresponding to private IP: " + privateIp + " and destination port: " + destPort + " does not exist.");
            }

            xml = SrxXml.DEST_NAT_RULE_ADD.getXml();
            xml = replaceXmlValue(xml, "rule-set", _publicZone);
            xml = replaceXmlValue(xml, "from-zone", _publicZone);
            xml = replaceXmlValue(xml, "rule-name", ruleName);
            xml = replaceXmlValue(xml, "public-address", publicIp);
            xml = replaceXmlValue(xml, "src-port", String.valueOf(srcPort));
            xml = replaceXmlValue(xml, "pool-name", poolName);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add destination NAT rule from public IP " + publicIp + ", public port " + srcPort + ", private IP " + privateIp + ", and private port " + destPort);
            } else {
                return true;
            }

        case DELETE:
            if (!manageDestinationNatRule(SrxCommand.CHECK_IF_EXISTS, publicIp, privateIp, srcPort, destPort)) {
                return true;
            }

            xml = SrxXml.DEST_NAT_RULE_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "rule-set", _publicZone);
            xml = replaceXmlValue(xml, "from-zone", _publicZone);
            xml = replaceXmlValue(xml, "rule-name", ruleName);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to delete destination NAT rule from public IP " + publicIp + ", public port " + srcPort + ", private IP " + privateIp + ", and private port " + destPort);
            } else {
                return true;
            }

        default:
View Full Code Here

            xml = SrxXml.SRC_NAT_POOL_ADD.getXml();
            xml = replaceXmlValue(xml, "pool-name", poolName);
            xml = replaceXmlValue(xml, "address", publicIp + "/32");

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add source NAT pool for public IP " + publicIp);
            } else {
                return true;
            }

        case DELETE:
            if (!manageSourceNatPool(SrxCommand.CHECK_IF_EXISTS, publicIp)) {
                return true;
            }

            if (manageSourceNatPool(SrxCommand.CHECK_IF_IN_USE, publicIp)) {
                return true;
            }

            xml = SrxXml.SRC_NAT_POOL_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "pool-name", poolName);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to delete source NAT pool for public IP " + publicIp);
            } else {
                return true;
            }

        default:
View Full Code Here

            if (manageSourceNatRule(SrxCommand.CHECK_IF_EXISTS, publicIp, privateSubnet)) {
                return true;
            }

            if (!manageSourceNatPool(SrxCommand.CHECK_IF_EXISTS, publicIp)) {
                throw new ExecutionException("The source NAT pool corresponding to " + publicIp + " does not exist.");
            }

            xml = SrxXml.SRC_NAT_RULE_ADD.getXml();
            xml = replaceXmlValue(xml, "rule-set", _privateZone);
            xml = replaceXmlValue(xml, "from-zone", _privateZone);
            xml = replaceXmlValue(xml, "to-zone", _publicZone);
            xml = replaceXmlValue(xml, "rule-name", ruleName);
            xml = replaceXmlValue(xml, "private-subnet", privateSubnet);
            xml = replaceXmlValue(xml, "pool-name", poolName);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add source NAT rule for public IP " + publicIp + " and private subnet " + privateSubnet);
            } else {
                return true;
            }

        case DELETE:
            if (!manageSourceNatRule(SrxCommand.CHECK_IF_EXISTS, publicIp, privateSubnet)) {
                return true;
            }

            xml = SrxXml.SRC_NAT_RULE_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "rule-set", _privateZone);
            xml = replaceXmlValue(xml, "from-zone", _privateZone);
            xml = replaceXmlValue(xml, "rule-name", ruleName);

            if (!sendRequestAndCheckResponse(command, xml, "name", ruleName)) {
                throw new ExecutionException("Failed to delete source NAT rule for public IP " + publicIp + " and private subnet " + privateSubnet);
            } else {
                return true;
            }

        default:
View Full Code Here

        }
    }

    private boolean manageAddressBookEntry(SrxCommand command, String zone, String ip, String entryName) throws ExecutionException {
        if (!zone.equals(_publicZone) && !zone.equals(_privateZone)) {
            throw new ExecutionException("Invalid zone.");
        }

        if (entryName == null) {
          entryName = genAddressBookEntryName(ip);
        }

        String xml;

        switch (command) {

        case CHECK_IF_EXISTS:
            xml = SrxXml.ADDRESS_BOOK_ENTRY_GETONE.getXml();
            xml = setDelete(xml, false);
            xml = replaceXmlValue(xml, "zone", zone);
            xml = replaceXmlValue(xml, "entry-name", entryName);
            return sendRequestAndCheckResponse(command, xml, "name", entryName);

        case CHECK_IF_IN_USE:
            // Check if any security policies refer to this address book entry
            xml = SrxXml.SECURITY_POLICY_GETALL.getXml();
            String fromZone = zone.equals(_publicZone) ? _privateZone : _publicZone;
            xml = replaceXmlValue(xml, "from-zone", fromZone);
            xml = replaceXmlValue(xml, "to-zone", zone);
            return sendRequestAndCheckResponse(command, xml, "destination-address", entryName);

        case ADD:
            if (manageAddressBookEntry(SrxCommand.CHECK_IF_EXISTS, zone, ip, entryName)) {
                return true;
            }

            xml = SrxXml.ADDRESS_BOOK_ENTRY_ADD.getXml();
            xml = replaceXmlValue(xml, "zone", zone);
            xml = replaceXmlValue(xml, "entry-name", entryName);
            xml = replaceXmlValue(xml, "ip", ip);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to add address book entry for IP " + ip + " in zone " + zone);
            } else {
                return true;
            }

        case DELETE:
            if (!manageAddressBookEntry(SrxCommand.CHECK_IF_EXISTS, zone, ip, entryName)) {
                return true;
            }

            if (manageAddressBookEntry(SrxCommand.CHECK_IF_IN_USE, zone, ip, entryName)) {
                return true;
            }

            xml = SrxXml.ADDRESS_BOOK_ENTRY_GETONE.getXml();
            xml = setDelete(xml, true);
            xml = replaceXmlValue(xml, "zone", zone);
            xml = replaceXmlValue(xml, "entry-name", entryName);

            if (!sendRequestAndCheckResponse(command, xml)) {
                throw new ExecutionException("Failed to delete address book entry for IP " + ip + " in zone " + zone);
            } else {
                return true;
            }

        default:
View Full Code Here

            offset = (type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS) || type.equals(SecurityPolicyType.SECURITYPOLICY_EGRESS_DEFAULT))? 1 : 0;
            protocol = getProtocol(applicationComponents[offset + 0]);
            startPort = Integer.parseInt(applicationComponents[offset + 1]);
            endPort = Integer.parseInt(applicationComponents[offset + 2]);
            } catch (Exception e) {
            throw new ExecutionException(errorMsg);
        }

        return new Object[]{protocol, startPort, endPort};
    }
View Full Code Here

TOP

Related Classes of com.cloud.utils.exception.ExecutionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.