Package net.juniper.contrail.api

Examples of net.juniper.contrail.api.ApiConnector


    @Override
    public void update(ModelController controller) throws InternalErrorException, IOException {

        assert _initialized;

        ApiConnector api = controller.getApiAccessor();
        VlanDao vlanDao = controller.getVlanDao();
        VirtualNetwork vn = _vn;

        if (!isDynamicNetwork()) {
            _vn = (VirtualNetwork)controller.getApiAccessor().findById(VirtualNetwork.class, _uuid);
            return;
        }

        assert _uuid != null : "uuid is not set";

        if (_vn == null) {
            vn = _vn = (VirtualNetwork)controller.getApiAccessor().findById(VirtualNetwork.class, _uuid);
            if (vn == null) {
                vn = new VirtualNetwork();
                if (_projectId != null) {
                    Project project;
                    try {
                        project = (Project)api.findById(Project.class, _projectId);
                    } catch (IOException ex) {
                        s_logger.debug("project read", ex);
                        throw new CloudRuntimeException("Failed to read project", ex);
                    }
                    vn.setParent(project);
                }
                vn.setName(_name);
                vn.setUuid(_uuid);
            }
        }

        if (_policyModel == null) {
            vn.clearNetworkPolicy();
        } else if (!_policyModel.hasPolicyRules()) {
            vn.clearNetworkPolicy();
            _policyModel.removeSuccessor(this);
        } else {
            vn.setNetworkPolicy(_policyModel.getPolicy(), new VirtualNetworkPolicyType(
                    new VirtualNetworkPolicyType.SequenceType(1, 0), null));
        }

        if (_ipam == null) {
            NetworkIpam ipam = null;
            try {
                String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam");
                if (ipam_id == null) {
                    s_logger.debug("could not find default-network-ipam");
                    return;
                }
                ipam = (NetworkIpam)api.findById(NetworkIpam.class, ipam_id);
                if (ipam == null) {
                    s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id);
                    return;
                }
            } catch (IOException ex) {
                s_logger.error(ex);
                return;
            }
            _ipam = ipam;
        }

        if (_prefix != null) {
            VnSubnetsType subnet = new VnSubnetsType();
            String[] addr_pair = _prefix.split("\\/");
            subnet.addIpamSubnets(new SubnetType(addr_pair[0], Integer.parseInt(addr_pair[1])), _gateway);
            vn.setNetworkIpam(_ipam, subnet);
        } else if (_trafficType == TrafficType.Public) {
            vn.clearNetworkIpam();
            /* Subnet information for Public is stored in the vlan table */
            List<VlanVO> vlan_list = vlanDao.listVlansByNetworkId(_id);
            for (VlanVO vlan : vlan_list) {
                String cidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask());
                int slash = cidr.indexOf('/');
                String ip_addr = cidr.substring(0, slash);
                int plen = Integer.parseInt(cidr.substring(slash + 1));
                VnSubnetsType subnet = new VnSubnetsType();
                subnet.addIpamSubnets(new SubnetType(ip_addr, plen), vlan.getVlanGateway());
                vn.addNetworkIpam(_ipam, subnet);
            }
        }

        if (_vn == null) {
            try {
                api.create(vn);
            } catch (Exception ex) {
                s_logger.debug("virtual-network create", ex);
                throw new CloudRuntimeException("Failed to create virtual-network", ex);
            }
            _vn = vn;
        } else {
            try {
                api.update(vn);
            } catch (IOException ex) {
                s_logger.warn("virtual-network update", ex);
                throw new CloudRuntimeException("Unable to update virtual-network object", ex);
            }
        }
View Full Code Here


            successor.update(controller);
        }
    }

    public void read(ModelController controller) {
        ApiConnector api = controller.getApiAccessor();
        VlanDao vlanDao = controller.getVlanDao();
        try {
            _vn = (VirtualNetwork)api.findById(VirtualNetwork.class, _uuid);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (_vn == null) {
            return;
        }
        if (_ipam == null) {
            NetworkIpam ipam = null;
            try {
                String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam");
                if (ipam_id == null) {
                    s_logger.debug("could not find default-network-ipam");
                    return;
                }
                ipam = (NetworkIpam)api.findById(NetworkIpam.class, ipam_id);
                if (ipam == null) {
                    s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id);
                    return;
                }
            } catch (IOException ex) {
View Full Code Here

    @Override
    public boolean verify(ModelController controller) {
        assert _initialized : "initialized is false";
    assert _uuid != null : "uuid is not set";

    ApiConnector api = controller.getApiAccessor();
    VlanDao vlanDao = controller.getVlanDao();

    try {
        _vn = (VirtualNetwork)api.findById(VirtualNetwork.class, _uuid);
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (_vn == null) {
View Full Code Here

    /**
     * Recreate the model object from the Contrail API which is the master for this type of object.
     * @param siObj
     */
    public void build(ModelController controller, ServiceInstance siObj) {
        ApiConnector api = controller.getApiAccessor();
        _serviceInstance = siObj;
        _fqName = StringUtils.join(siObj.getQualifiedName(), ':');
        ServiceInstanceType props = siObj.getProperties();
        // TODO: read management network names and cache network objects.
        ObjectReference ref = siObj.getServiceTemplate().get(0);
        if (ref != null) {
            try {
                ServiceTemplate tmpl = (ServiceTemplate)api.findById(ServiceTemplate.class, ref.getUuid());
                _templateId = tmpl.getUuid();
            } catch (IOException ex) {
                s_logger.warn("service-template read", ex);
            }
        }
View Full Code Here

    private ServiceInstance createServiceInstance(ModelController controller) {
        Project project = null;
        if (_projectId != null) {
            try {
                ApiConnector api = controller.getApiAccessor();
                project = (Project)api.findById(Project.class, _projectId);
            } catch (IOException ex) {
                s_logger.warn("project read", ex);
                throw new CloudRuntimeException("Unable to create service-instance object", ex);
            }
        }

        ServiceInstance si_obj = new ServiceInstance();
        if (project != null) {
            si_obj.setParent(project);
        }
        si_obj.setName(getName());
        si_obj.setServiceTemplate(_tmpl);
        si_obj.setProperties(new ServiceInstanceType(false, _mgmtName, _leftName, null, _rightName, null, new ServiceInstanceType.ServiceScaleOutType(1, false)));
        try {
            ApiConnector api = controller.getApiAccessor();
            api.create(si_obj);
        } catch (IOException ex) {
            s_logger.warn("service-instance create", ex);
            throw new CloudRuntimeException("Unable to create service-instance object", ex);
        }
View Full Code Here

        return policyModel;
    }

    @Override
    public void delete(ModelController controller) throws IOException {
        ApiConnector api = controller.getApiAccessor();
        clearServicePolicy(controller);
        if (_serviceInstance != null) {
            api.delete(_serviceInstance);
        }
    }
View Full Code Here

    }

    private ServiceTemplate locateServiceTemplate(ModelController controller) {
        ServiceTemplate tmpl;
        try {
            ApiConnector api = controller.getApiAccessor();
            tmpl = (ServiceTemplate)api.findById(ServiceTemplate.class, _templateId);
        } catch (IOException ex) {
            s_logger.warn("service-template read", ex);
            throw new CloudRuntimeException("Unable to create service-template object", ex);
        }
        if (tmpl == null) {
            tmpl = new ServiceTemplate();
            tmpl.setName(_templateName);
            tmpl.setUuid(_templateId);
            ServiceTemplateType props = new ServiceTemplateType("in-network", null, _templateUrl, false, null);
            tmpl.setProperties(props);
            try {
                ApiConnector api = controller.getApiAccessor();
                api.create(tmpl);
            } catch (IOException ex) {
                throw new CloudRuntimeException("Unable to create service-template object", ex);
            }
        }
        return tmpl;
View Full Code Here

            }           
        }       
    }

    public <T extends ApiPropertyBase> void deleteChildren(List<ObjectReference<T>> childs,  Class<?> childCls, StringBuffer syncLogMesg) throws Exception {
        final ApiConnector api = _manager.getApiConnector();
        if (childs == null) {
            syncLogMesg.append("no children of type: " + childCls.getName() + "\n");
            return;
        }
       
        syncLogMesg.append("delete children of type : " + DBSyncGeneric.getClassName(childCls) + "\n");
        String deleteChildMethod = "delete" + DBSyncGeneric.getClassName(childCls);
        Method method = null;
        Method methods[] = this.getClass().getMethods();
        for (int i = 0; i < methods.length; i++) {
            if(methods[i].getName().equalsIgnoreCase(deleteChildMethod)) {
                method = methods[i];
                break;
            }
        }
        int count = 0;
        for (ObjectReference<T> childRef: childs) {
            @SuppressWarnings("unchecked")
            ApiObjectBase child = (ApiObjectBase) api.findById((Class<? extends ApiObjectBase>)childCls, childRef.getUuid());
            if (method != null) {
               method.invoke(this, child, syncLogMesg);
            } else {
                deleteDefault(child, childCls, syncLogMesg);
            }
View Full Code Here

        }
        syncLogMesg.append("deleted children count : " + count + "\n");
    }

    public void deleteDefault(ApiObjectBase vnc, Class<?> cls, StringBuffer syncLogMesg) throws IOException {
        final ApiConnector api = _manager.getApiConnector();
        api.delete(vnc);
        syncLogMesg.append(cls.getCanonicalName() + "# VNC: " + vnc.getName() + " deleted\n");
    }
View Full Code Here

    /*
     *  Domain Synchronization methods
     */
    public boolean syncDomain() throws Exception {
        final ApiConnector api = _manager.getApiConnector();
        try {
            List<?> dbList = _domainDao.listAll();
            @SuppressWarnings("unchecked")
            List<?> vncList = (List<net.juniper.contrail.api.types.Domain>) api.list(net.juniper.contrail.api.types.Domain.class, null);
            return _dbSync.syncGeneric(net.juniper.contrail.api.types.Domain.class, dbList, vncList);
        } catch (Exception ex) {
            s_logger.warn("syncDomain", ex);
            throw ex;
        }
View Full Code Here

TOP

Related Classes of net.juniper.contrail.api.ApiConnector

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.