Package net.juniper.contrail.api

Examples of net.juniper.contrail.api.ApiConnector


    /**
     * The service-instance model list is build as a result of synchronizing virtual-machines.
     * @return
     */
    public boolean syncServiceInstance() {
        final ApiConnector api = _manager.getApiConnector();
        boolean inSync;
        try {
            @SuppressWarnings("unchecked")
            List<ServiceInstance> siList = (List<ServiceInstance>)api.list(ServiceInstance.class, null);
            java.util.Collections.sort(siList, new ServiceInstanceComparator());
            DBSyncGeneric.SyncStats stats = new DBSyncGeneric.SyncStats();
            _dbSync.syncCollections(ServiceInstance.class, _manager.getDatabase().getServiceInstances(), siList, _rwMode, stats);
            inSync = stats.create == 0 && stats.delete == 0;
        } catch (Exception ex) {
View Full Code Here


    public void testCreateVirtualMachine() throws IOException {

        String uuid = UUID.randomUUID().toString();
        ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
        ModelController controller      = mock(ModelController.class);
        ApiConnector api = new ApiConnectorMock(null, 0);
        when(controller.getManager()).thenReturn(contrailMgr);
        when(controller.getApiAccessor()).thenReturn(api);

        // Create Virtual-Network (VN)
        NetworkVO network = mock(NetworkVO.class);
View Full Code Here

        ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);

        controller = mock(ModelController.class);
        VlanDao vlanDao = mock(VlanDao.class);

        ApiConnector api = mock(ApiConnectorMock.class);

        //Mock classes/methods
        when(controller.getManager()).thenReturn(contrailMgr);
        when(controller.getApiAccessor()).thenReturn(api);
        when(controller.getVlanDao()).thenReturn(vlanDao);

        //Policy References used by vnModel1
        List<ObjectReference<VirtualNetworkPolicyType>> policyRefs1 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
        ObjectReference<VirtualNetworkPolicyType> objectReference1 = new ObjectReference<VirtualNetworkPolicyType>();
        policyRefs1.add(objectReference1);

        //Policy References used by vnModel2
        List<ObjectReference<VirtualNetworkPolicyType>> policyRefs2 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
        ObjectReference<VirtualNetworkPolicyType> objectReference2 = new ObjectReference<VirtualNetworkPolicyType>();
        policyRefs2.add(objectReference2);

        //Policy References used by vnModel3
        List<ObjectReference<VirtualNetworkPolicyType>> policyRefs3 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
        ObjectReference<VirtualNetworkPolicyType> objectReference3 = new ObjectReference<VirtualNetworkPolicyType>();
        objectReference3.setReference(Arrays.asList(""), null, null, UUID.randomUUID().toString());

        policyRefs3.add(objectReference3);

        //Network to be compared with
        VirtualNetwork vn = mock(VirtualNetwork.class);
        when(api.findById(VirtualNetwork.class, uuid)).thenReturn(vn);

        //Network to be compared with
        VirtualNetwork vn1 = mock(VirtualNetwork.class);
        when(api.findById(VirtualNetwork.class, uuid1)).thenReturn(vn1);
        when(vn1.getNetworkPolicy()).thenReturn(policyRefs1);

        //Network to be compared to
        VirtualNetwork vn2 = mock(VirtualNetwork.class);
        when(api.findById(VirtualNetwork.class, uuid2)).thenReturn(vn2);
        when(vn2.getNetworkPolicy()).thenReturn(policyRefs2);

        //Network to be compared to
        VirtualNetwork vn3 = mock(VirtualNetwork.class);
        when(api.findById(VirtualNetwork.class, uuid3)).thenReturn(vn3);
        when(vn3.getNetworkPolicy()).thenReturn(policyRefs3);

        //Virtual-Network 1
        NetworkVO network1 = mock(NetworkVO.class);
        when(network1.getName()).thenReturn("testnetwork");
View Full Code Here

    public void testCreateVirtualNetwork() throws IOException {

        String uuid = UUID.randomUUID().toString();
        ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
        ModelController controller      = mock(ModelController.class);
        ApiConnector api = new ApiConnectorMock(null, 0);
        when(controller.getManager()).thenReturn(contrailMgr);
        when(controller.getApiAccessor()).thenReturn(api);

        // Create Virtual-Network (VN)
        NetworkVO network = mock(NetworkVO.class);
View Full Code Here

        }
        if (right.getTrafficType() == TrafficType.Guest) {
            _networkModel.checkNetworkPermissions(owner, right);
        }

        final ApiConnector api = _manager.getApiConnector();
        VirtualNetworkModel leftModel = _manager.getDatabase().lookupVirtualNetwork(left.getUuid(),
                _manager.getCanonicalName(left), left.getTrafficType());
        if (leftModel == null) {
            throw new CloudRuntimeException("Unable to read virtual-network object");
        }
        VirtualNetworkModel rightModel = _manager.getDatabase().lookupVirtualNetwork(right.getUuid(),
                _manager.getCanonicalName(right), right.getTrafficType());
        if (rightModel == null) {
            throw new CloudRuntimeException("Unable to read virtual-network object");
        }

        net.juniper.contrail.api.types.Project project;
        try {
            project = _manager.getVncProject(owner.getDomainId(), owner.getAccountId());
        } catch (IOException ex) {
            s_logger.warn("read project", ex);
            throw new CloudRuntimeException(ex);
        }

        try {
            final String srvid = api.findByName(ServiceInstance.class, project, name);
            if (srvid != null) {
                throw new InvalidParameterValueException("service-instance " + name + " already exists uuid=" + srvid);
            }
        } catch (IOException ex) {
            s_logger.warn("service-instance lookup", ex);
View Full Code Here

    public void delete(ModelController controller) throws IOException {
        for (ModelObject successor : successors()) {
            successor.delete(controller);
        }

        ApiConnector api = controller.getApiAccessor();
        api.delete(VirtualMachineInterface.class, _uuid);
    }
View Full Code Here

        }
        if (_vnModel == null) {
            throw new InternalErrorException("virtual-network not set on VMI: " + _uuid);
        }
        ContrailManager manager = controller.getManager();
        ApiConnector api = controller.getApiAccessor();

        VirtualMachineInterface vmi = (VirtualMachineInterface)api.findById(VirtualMachineInterface.class, _uuid);
        boolean create = false;
        if (vmi == null) {
            create = true;
            vmi = new VirtualMachineInterface();
            vmi.setParent(_vmModel.getVirtualMachine());
            vmi.setName(manager.getVifNameByVmName(_vmModel.getInstanceName(), _deviceId));
            vmi.setUuid(_uuid);
            vmi.setVirtualNetwork(_vnModel.getVirtualNetwork());
        } else {
            // Do not try to update VMI to routing-instance references. These are managed by schema-transformer.
            vmi.clearRoutingInstance();
        }
        _vmi = vmi;
        if (_macAddress != null) {
            MacAddressesType mac = new MacAddressesType();
            mac.addMacAddress(_macAddress);
            vmi.setMacAddresses(mac);
        }

        if (_serviceTag != null) {
            vmi.setProperties(new VirtualMachineInterfacePropertiesType(_serviceTag, null));
        }

        if (create) {
            if (!api.create(vmi)) {
                throw new InternalErrorException("Unable to create virtual-machine-interface " + _uuid);
            }
        } else {
            if (!api.update(vmi)) {
                throw new InternalErrorException("Unable to update virtual-machine-interface " + _uuid);
            }
        }

        api.read(vmi);

        int ipCount = 0;
        for (ModelObject successor : successors()) {
            if (successor.getClass() == InstanceIpModel.class) {
                ipCount++;
View Full Code Here

     * @param controller
     * @param serviceUuid
     */
    private void buildServiceInstance(ModelController controller, String serviceUuid) {
        ContrailManager manager = controller.getManager();
        ApiConnector api = controller.getApiAccessor();
        _serviceUuid = serviceUuid;

        ServiceInstance siObj;
        try {
            siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid);
        } catch (IOException ex) {
            s_logger.warn("service-instance read", ex);
            throw new CloudRuntimeException("Unable to read service-instance object", ex);
        }

View Full Code Here

        return _uuid.compareTo(other._uuid);
    }

    @Override
    public void delete(ModelController controller) throws IOException {
        ApiConnector api = controller.getApiAccessor();
        for (ModelObject successor : successors()) {
            successor.delete(controller);
        }

        try {
            api.delete(VirtualMachine.class, _uuid);
        } catch (IOException ex) {
            s_logger.warn("virtual-machine delete", ex);
        }

        if (_serviceModel != null) {
View Full Code Here

    }

    @Override
    public void update(ModelController controller) throws InternalErrorException, IOException {
        assert _initialized;
        ApiConnector api = controller.getApiAccessor();

        VirtualMachine vm = _vm;
        if (vm == null) {
            _vm = vm = (VirtualMachine)api.findById(VirtualMachine.class, _uuid);
            if (vm == null) {
                vm = new VirtualMachine();
                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);
                    }
                    vm.setParent(project);
                }
                vm.setName(_instanceName);
                vm.setUuid(_uuid);
            }
        }

        if (_serviceModel != null) {
            vm.setServiceInstance(_serviceModel.getServiceInstance());
        }

        if (_vm == null) {
            try {
                api.create(vm);
            } catch (Exception ex) {
                s_logger.debug("virtual-machine create", ex);
                throw new CloudRuntimeException("Failed to create virtual-machine", ex);
            }
            _vm = vm;
        } else {
            try {
                api.update(vm);
            } catch (IOException ex) {
                s_logger.warn("virtual-machine update", ex);
                throw new CloudRuntimeException("Unable to update virtual-machine object", 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.