當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。