Package io.fathom.cloud.protobuf.CloudModel

Examples of io.fathom.cloud.protobuf.CloudModel.InstanceData


        if (vip.getData().hasInstanceId()) {
            log.warn("Virtual IP attached to new machine: {}", ip);
            throw new IllegalStateException();
        }

        InstanceData instance = computeServices.findInstance(project.getId(), instanceId);
        if (instance == null) {
            log.warn("Instance not found, giving up: {}", instanceId);
            return false;
        }

        SchedulerHost host = scheduler.findHost(instance.getHostId());
        if (host == null) {
            throw new IllegalStateException();
        }

        try (ConfigurationOperation config = host.startConfiguration()) {
View Full Code Here


    }

    public InstanceData addRemoveSecurityGroup(Project project, long instanceId, SecurityGroupData sg, boolean remove)
            throws CloudException {
        NumberedItemCollection<InstanceData> store = repository.getInstances(project.getId());
        InstanceData instance = store.find(instanceId);
        if (instance == null) {
            throw new IllegalArgumentException();
        }

        InstanceData.Builder b = InstanceData.newBuilder(instance);
        Set<Long> securityGroups = Sets.newHashSet(b.getSecurityGroupIdList());
        if (remove) {
            securityGroups.remove(sg.getId());
        } else {
            securityGroups.add(sg.getId());
        }

        b.clearSecurityGroupId();
        b.addAllSecurityGroupId(securityGroups);

        InstanceData updated = store.update(b);
        asyncTasks.updateInstanceSecurityGroups(project, updated);
        return updated;
    }
View Full Code Here

    NetworkPools networkPools;

    public InstanceData updateInstance(final InstanceData instance, final InstanceData.Builder changes)
            throws CloudException {
        NumberedItemCollection<InstanceData> instances = computeStore.getInstances(instance.getProjectId());
        InstanceData read = instances.find(instance.getId());
        InstanceData.Builder b = InstanceData.newBuilder(read);
        b.mergeFrom(changes.build());
        return instances.update(b);
    }
View Full Code Here

        // time? Maybe as part of an accounting sweep?
    }

    public InstanceData updateInstance(Project project, long id, String name) throws CloudException {
        NumberedItemCollection<InstanceData> store = repository.getInstances(project.getId());
        InstanceData instance = store.find(id);
        if (instance == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }

        InstanceData.Builder b = InstanceData.newBuilder(instance);
View Full Code Here

        return computeRepository.getInstances(project.getId()).find(instanceId);
    }

    public InstanceData replaceMetadata(Project project, long instanceId, Map<String, String> model, boolean replaceAll)
            throws CloudException {
        InstanceData instance = findInstance(project, instanceId);
        if (instance == null) {
            throw new IllegalArgumentException("Instance not found: " + instanceId);
        }

        InstanceData.Builder b = InstanceData.newBuilder(instance);
        if (replaceAll) {
            b.clearMetadata();

            MetadataData.Builder mb = b.getMetadataBuilder();

            for (Entry<String, String> entry : model.entrySet()) {
                MetadataEntryData.Builder eb = mb.addEntryBuilder();
                eb.setKey(entry.getKey());
                eb.setValue(entry.getValue());
            }
        } else {
            MetadataData.Builder mb = b.getMetadataBuilder();

            for (Entry<String, String> entry : model.entrySet()) {
                if (!setMetadataKey(mb, entry.getKey(), entry.getValue())) {
                    throw new IllegalArgumentException();
                }
            }
        }

        InstanceData updated = computeRepository.getInstances(project.getId()).update(b);
        magicMetadata.instanceUpdated(project, updated);
        return updated;
    }
View Full Code Here

        return model;
    }

    public InstanceData replaceMetadataKey(Project project, long instanceId, String key, String value)
            throws CloudException {
        InstanceData instance = findInstance(project, instanceId);
        if (instance == null) {
            throw new IllegalArgumentException();
        }
        InstanceData.Builder b = InstanceData.newBuilder(instance);

        MetadataData.Builder mb = b.getMetadataBuilder();

        if (!setMetadataKey(mb, key, value)) {
            log.warn("Could not replace metadata key: {}={}.  Metadata={}", key, value, mb.build());
            throw new IllegalArgumentException();
        }

        InstanceData updated = computeRepository.getInstances(project.getId()).update(b);
        magicMetadata.instanceUpdated(project, updated);
        return updated;
    }
View Full Code Here

        if (vip.getData().getInstanceId() != instanceId) {
            log.warn("Virtual IP not attached to same machine, giving up: {}", ip);
            throw new IllegalStateException();
        }

        InstanceData instance = computeServices.findInstance(project.getId(), instanceId);
        if (instance == null) {
            log.warn("Instance not found, giving up: {}", instanceId);
            throw new IllegalStateException();
        }

        SchedulerHost host = scheduler.findHost(instance.getHostId());
        if (host == null) {
            throw new IllegalStateException();
        }

        try (ConfigurationOperation config = host.startConfiguration()) {
View Full Code Here

        List<InstanceData> stopInstances = Lists.newArrayList();

        for (String instanceEc2Id : instanceEc2Ids) {
            long instanceId = decodeEc2Id("i-", instanceEc2Id);
            InstanceData instance = instanceStateStore.getInstances(getProject().getId()).find(instanceId);
            if (instance == null) {
                throw new CloudException("The instance ID '" + instanceEc2Id + "' does not exist");
            }
            stopInstances.add(instance);
        }

        asyncTasks.stopInstances(stopInstances);
        for (InstanceData instance : stopInstances) {
            // This is a very abbreviated state
            InstanceStateChange instanceStateChange = new InstanceStateChange();
            instanceStateChange.instanceId = toEc2InstanceId(instance.getId());

            instanceStateChange.currentState = buildInstanceState(instance);
            instanceStateChange.previousState = buildInstanceState(CloudModel.InstanceState.STOPPING);

            response.instances.add(instanceStateChange);
View Full Code Here

    @PathParam("serverId")
    long instanceId;

    @GET
    public ServerMetadata getMetadata() throws CloudException {
        InstanceData instance = getInstance();

        return buildResponse(instance);
    }
View Full Code Here

    }

    @GET
    @Path("{key}")
    public ServerMetadata getMetadataKey(@PathParam("key") String key) throws CloudException {
        InstanceData instance = getInstance();

        ServerMetadata response = buildResponse(instance);

        String value = response.metadata.get(key);
        response.metadata.clear();
View Full Code Here

TOP

Related Classes of io.fathom.cloud.protobuf.CloudModel.InstanceData

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.