当前位置: 首页>>代码示例>>Java>>正文


Java CloudException类代码示例

本文整理汇总了Java中jetbrains.buildServer.clouds.CloudException的典型用法代码示例。如果您正苦于以下问题:Java CloudException类的具体用法?Java CloudException怎么用?Java CloudException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CloudException类属于jetbrains.buildServer.clouds包,在下文中一共展示了CloudException类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNetworkIdentity

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public String getNetworkIdentity(String instanceId) {
    try {
        JobId jobId = JobId.fromString(instanceIdJobMap.get(instanceId));
        JobStatus jobStatus = getHeliosResult(heliosClient.jobStatus(jobId));
        if (jobStatus == null) {
            LOG.warn("Trying to read network identity of non-existent job " + jobId.getName());
            return null;
        }

        String host = jobStatus.getTaskStatuses().keySet().stream()
                .findFirst()
                .orElseThrow(() -> new CloudException("Container " + instanceId + " not deployed on any host"));
        // TODO: How to do this?
        return null;
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new CloudException("Failed to read network information from instance " + instanceId, e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:20,代码来源:HeliosContainerProvider.java

示例2: getStartedTime

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public Date getStartedTime(String instanceId) {
    try {
        JobId jobId = JobId.fromString(instanceIdJobMap.get(instanceId));
        JobStatus jobStatus = getHeliosResult(heliosClient.jobStatus(jobId));
        if (jobStatus == null) {
            LOG.warn("Trying to read start time of non-existent job " + jobId.getName());
            return null;
        }

        String host = jobStatus.getTaskStatuses().keySet().stream()
                .findFirst()
                .orElseThrow(() -> new CloudException("Container " + instanceId + " not deployed on any host"));
        return new Date(jobStatus.getTaskStatuses().get(host).getJob().getCreated());
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new CloudException("Failed to read start time information from instance " + instanceId, e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:19,代码来源:HeliosContainerProvider.java

示例3: startInstance

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public ContainerCloudInstance startInstance(@NotNull String instanceId, @NotNull ContainerCloudImage image, @NotNull CloudInstanceUserData tag) {
    try {
        LOG.debug("Pulling image " + image.getId());
        dockerClient.pull(image.getId());

        List<String> environment = new ArrayList<>();
        tag.getCustomAgentConfigurationParameters().forEach((key, value) -> environment.add(key + "=" + value));

        ContainerConfig cfg = ContainerConfig.builder()
                .image(image.getId())
                .env(environment)
                .build();
        ContainerCreation creation = dockerClient.createContainer(cfg, instanceId);
        LOG.debug("Starting image " + image.getId());
        dockerClient.startContainer(creation.id());

        return new ContainerCloudInstance(instanceId, image, this);
    } catch (Exception e) {
        throw new CloudException("Failed to start instance of image " + image.getId(), e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:23,代码来源:DockerSocketContainerProvider.java

示例4: getPropertiesProcessor

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
public static PropertiesProcessor getPropertiesProcessor() {
    return properties -> {
        if (!properties.containsKey(ContainerCloudConstants.ProfileParameterName_ContainerProvider)) {
            // There's no use trying to validate anything more at this point (shouldn't ever happen anayway...)
            return Stream.of(
                    new InvalidProperty(ContainerCloudConstants.ProfileParameterName_ContainerProvider,
                            "Container provider not selected"))
                    .collect(Collectors.toList());
        }

        PropertiesProcessor specificProcessor;
        String provider = properties.get(ContainerCloudConstants.ProfileParameterName_ContainerProvider);
        switch (provider) {
            case ContainerCloudConstants.ProfileParameterValue_ContainerProvider_DockerSocket:
                specificProcessor = DockerSocketContainerProvider.getPropertiesProcessor();
                break;
            case ContainerCloudConstants.ProfileParameterValue_ContainerProvider_Helios:
                specificProcessor = HeliosContainerProvider.getPropertiesProcessor();
                break;
            default:
                throw new CloudException("Unknown container provider '" + provider + "'");
        }

        return specificProcessor.process(properties);
    };
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:27,代码来源:ContainerProviderFactory.java

示例5: stopInstance

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
public Task stopInstance(@NotNull final VmwareCloudInstance instance) {
  instance.setStatus(InstanceStatus.STOPPING);
  try {
    final VirtualMachine vm = findEntityByIdNameNullableOld(instance.getInstanceId(), VirtualMachine.class, null);
    if (vm == null){
      // VM no longer exists TW-47486
      instance.getImage().removeInstance(instance.getInstanceId());
      return emptyTask();
    }
    if (getInstanceStatus(vm) == InstanceStatus.STOPPED) {
      return emptyTask();
    }
    return doShutdown(instance, vm);
  } catch (Exception ex) {
    instance.updateErrors(TypedCloudErrorInfo.fromException(ex));
    throw new CloudException(ex.getMessage(),ex);
  }
}
 
开发者ID:JetBrains,项目名称:teamcity-vmware-plugin,代码行数:19,代码来源:VMWareApiConnectorImpl.java

示例6: getRandomMatchingHost

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
private String getRandomMatchingHost() {
    try {
        List<String> hosts = getHosts();
        if (hosts.size() == 0) {
            throw new CloudException("No Helios hosts matched conditions set in cloud profile!");
        }

        int idx = random.nextInt(hosts.size());
        return hosts.get(idx);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new CloudException("Could not get host to run agent on", e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:14,代码来源:HeliosContainerProvider.java

示例7: stopInstance

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public void stopInstance(@NotNull ContainerCloudInstance instance) {
    try {
        JobId jobId = JobId.fromString(instanceIdJobMap.get(instance.getInstanceId()));
        LOG.debug("Stopping Helios job " + jobId);
        JobStatus jobStatus = getHeliosResult(heliosClient.jobStatus(jobId));
        Set<String> hosts = jobStatus.getDeployments().keySet();

        for (String host : hosts) {
            LOG.debug("Undeploying " + jobId + " from " + host);
            JobUndeployResponse jobUndeployResponse = getHeliosResult(heliosClient.undeploy(jobId, host));
            if (jobUndeployResponse.getStatus() != JobUndeployResponse.Status.OK) {
                throw new CloudException("Failed to undeploy Helios job, status " + jobUndeployResponse.getStatus());
            }
        }

        LOG.debug("Undeploy finished, deleting job " + jobId);
        JobDeleteResponse jobDeleteResponse = getHeliosResult(heliosClient.deleteJob(jobId));
        if (jobDeleteResponse.getStatus() != JobDeleteResponse.Status.OK) {
            throw new CloudException("Failed to remove Helios job, status " + jobDeleteResponse.getStatus());
        }

        LOG.debug("Finished stopping instance " + instance.getInstanceId());
        instanceIdJobMap.remove(instance.getInstanceId());
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new CloudException("Failed to stop instance", e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:29,代码来源:HeliosContainerProvider.java

示例8: getError

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public String getError(String instanceId) {
    try {
        JobId jobId = JobId.fromString(instanceIdJobMap.get(instanceId));
        JobStatus jobStatus = getHeliosResult(heliosClient.jobStatus(jobId));
        if (jobStatus == null) {
            LOG.warn("Trying to read error state of non-existent job " + jobId);
            return null;
        }
        Set<String> hostStatuses = jobStatus.getTaskStatuses().keySet();
        if (hostStatuses.isEmpty()) {
            LOG.debug("Trying to read error state before job is deployed for job " + jobId);
            return null;
        }

        // There really should only ever be one host that the job is deployed to, but let's be thorough
        StringBuilder sb = new StringBuilder();
        for (String host : hostStatuses) {
            TaskStatus status = jobStatus.getTaskStatuses().get(host);
            if (status.getContainerError() != null && !status.getContainerError().isEmpty()) {
                sb.append(host).append(": ").append(status.getContainerError()).append("\n");
            }
        }
        return sb.toString();
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new CloudException("Failed to read error information from instance " + instanceId, e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:29,代码来源:HeliosContainerProvider.java

示例9: getStatus

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public InstanceStatus getStatus(String instanceId) {
    try {
        JobId jobId = JobId.fromString(instanceIdJobMap.get(instanceId));
        JobStatus jobStatus = getHeliosResult(heliosClient.jobStatus(jobId));
        if (jobStatus == null) {
            LOG.warn("Trying to read status of non-existent job " + jobId.getName());
            return InstanceStatus.UNKNOWN;
        }

        String host = jobStatus.getTaskStatuses().keySet().stream()
                .findFirst()
                .orElseThrow(() -> new CloudException("Container " + instanceId + " not deployed on any host"));
        TaskStatus.State state = jobStatus.getTaskStatuses().get(host).getState();

        if (state.equals(TaskStatus.State.RUNNING))
            return InstanceStatus.RUNNING;
        if (state.equals(TaskStatus.State.STOPPED) || state.equals(TaskStatus.State.EXITED))
            return InstanceStatus.STOPPED;
        if (state.equals(TaskStatus.State.FAILED))
            return InstanceStatus.ERROR;
        if (state.equals(TaskStatus.State.STARTING) || state.equals(TaskStatus.State.CREATING) || state.equals(TaskStatus.State.PULLING_IMAGE))
            return InstanceStatus.STARTING;
        if (state.equals(TaskStatus.State.STOPPING))
            return InstanceStatus.STOPPING;

        LOG.warn("Could not map state '" + state.toString() + "' to InstanceStatus");
        return InstanceStatus.UNKNOWN;
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LOG.warn("Could not fetch state for " + instanceId, e);
        return InstanceStatus.UNKNOWN;
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:34,代码来源:HeliosContainerProvider.java

示例10: stopInstance

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public void stopInstance(@NotNull ContainerCloudInstance instance) {
    try {
        LOG.debug("Stopping container " + instance.getInstanceId());
        dockerClient.stopContainer(instance.getInstanceId(), CONTAINER_STOP_TIMEOUT_SECONDS);
    } catch (InterruptedException | DockerException e) {
        throw new CloudException("Failed to stop instance " + instance.getInstanceId(), e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:10,代码来源:DockerSocketContainerProvider.java

示例11: getStartedTime

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public Date getStartedTime(String instanceId) {
    try {
        return dockerClient.inspectContainer(instanceId).created();
    } catch (Exception e) {
        throw new CloudException("Could not determine container start time", e);
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:9,代码来源:DockerSocketContainerProvider.java

示例12: getProvider

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
public static ContainerProvider getProvider(CloudClientParameters parameters) {
    String provider = parameters.getParameter(ContainerCloudConstants.ProfileParameterName_ContainerProvider);
    switch (provider) {
        case ContainerCloudConstants.ProfileParameterValue_ContainerProvider_DockerSocket:
            return new DockerSocketContainerProvider(parameters);
        case ContainerCloudConstants.ProfileParameterValue_ContainerProvider_Helios:
            return new HeliosContainerProvider(parameters);
        default:
            throw new CloudException("Unknown container provider '" + provider + "'");
    }
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:12,代码来源:ContainerProviderFactory.java

示例13: getImages

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@NotNull
@Override
public Collection<VmwareCloudImage> getImages() throws CloudException {
  if (myGetImagesCalled != null)
    assertNull(myGetImagesCalled.put(this, true));

  return super.getImages();
}
 
开发者ID:JetBrains,项目名称:teamcity-vmware-plugin,代码行数:9,代码来源:VmwarePooledUpdateInstanceTaskTest.java

示例14: startInstance

import jetbrains.buildServer.clouds.CloudException; //导入依赖的package包/类
@Override
public ContainerCloudInstance startInstance(@NotNull String instanceId, @NotNull ContainerCloudImage image, @NotNull CloudInstanceUserData tag) {
    Job.Builder jobBuilder = Job.newBuilder()
            .setImage(image.getId())
            .setName("container-cloud-agent")
            .setVersion(instanceId);
    // Add all tag custom configuration as environment vars
    tag.getCustomAgentConfigurationParameters().forEach(jobBuilder::addEnv);
    Job jobDescriptor = jobBuilder.build();

    JobDeployResponse jobDeployResponse;
    String id;
    try {
        CreateJobResponse jobResponse = getHeliosResult(heliosClient.createJob(jobDescriptor));
        id = jobResponse.getId();

        List<String> jobCreationErrors = jobResponse.getErrors();
        if (!jobCreationErrors.isEmpty()) {
            String errorList = jobCreationErrors.stream().collect(Collectors.joining("\n"));
            throw new CloudException("Failed to create Helios job, errors were reported:\n" + errorList);
        }
        if (jobResponse.getStatus() != CreateJobResponse.Status.OK) {
            throw new CloudException("Failed to create Helios job, status is '" + jobResponse.getStatus() + "', not 'OK'");
        }

        String host = getRandomMatchingHost(); // TODO: Implement some more intelligent host picking strategy? (look at host stats like memory etc)
        LOG.debug("Deploying job " + id + " on host " + host);
        jobDeployResponse = getHeliosResult(heliosClient.deploy(Deployment.of(JobId.fromString(id), Goal.START), host));
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new CloudException("Failed to start Helios job", e);
    }

    if (jobDeployResponse.getStatus() != JobDeployResponse.Status.OK) {
        throw new CloudException("Helios job status is '" + jobDeployResponse.getStatus() + "' not 'OK'");
    }
    LOG.debug("Started Helios job " + id);

    ContainerCloudInstance cloudInstance = new ContainerCloudInstance(instanceId, image, this);
    instanceIdJobMap.put(instanceId, id);
    return cloudInstance;
}
 
开发者ID:carlpett,项目名称:teamcity-container-cloud,代码行数:42,代码来源:HeliosContainerProvider.java


注:本文中的jetbrains.buildServer.clouds.CloudException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。