jetbrains.buildServer.serverSide.TeamCityProperties Java Examples
The following examples show how to use
jetbrains.buildServer.serverSide.TeamCityProperties.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: S3Util.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 6 votes |
@NotNull public static Map<String, String> validateParameters(@NotNull final Map<String, String> params, final boolean acceptReferences) { final Map<String, String> commonErrors = AWSCommonParams.validate(params, acceptReferences); if (!commonErrors.isEmpty()) { return commonErrors; } final Map<String, String> invalids = new HashMap<>(); if (StringUtil.isEmptyOrSpaces(getBucketName(params))) { invalids.put(beanPropertyNameForBucketName(), "S3 bucket name must not be empty"); } final String pathPrefix = params.getOrDefault(S3_PATH_PREFIX_SETTING, ""); if (TeamCityProperties.getBoolean("teamcity.internal.storage.s3.bucket.prefix.enable") && !StringUtil.isEmptyOrSpaces(pathPrefix)) { if (pathPrefix.length() > OUT_MAX_PREFIX_LENGTH) { invalids.put(S3_PATH_PREFIX_SETTING, "Should be less than " + OUT_MAX_PREFIX_LENGTH + " characters"); } if (!OUR_OBJECT_KEY_PATTERN.matcher(pathPrefix).matches()) { invalids.put(S3_PATH_PREFIX_SETTING, "Should match the regexp [" + OUR_OBJECT_KEY_PATTERN.pattern() + "]"); } } return invalids; }
Example #2
Source File: S3PreSignedUrlProviderImpl.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 6 votes |
@NotNull @Override public String getPreSignedUrl(@NotNull HttpMethod httpMethod, @NotNull String bucketName, @NotNull String objectKey, @NotNull Map<String, String> params) throws IOException { try { final Callable<String> resolver = getUrlResolver(httpMethod, bucketName, objectKey, params); if (httpMethod == HttpMethod.GET) { return TeamCityProperties.getBoolean(TEAMCITY_S3_PRESIGNURL_GET_CACHE_ENABLED) ? myGetLinksCache.get(getCacheIdentity(params, objectKey, bucketName), resolver) : resolver.call(); } else { return resolver.call(); } } catch (Exception e) { final Throwable cause = e.getCause(); final AWSException awsException = cause != null ? new AWSException(cause) : new AWSException(e); final String details = awsException.getDetails(); if (StringUtil.isNotEmpty(details)) { final String message = awsException.getMessage() + details; LOG.warn(message); } throw new IOException(String.format( "Failed to create pre-signed URL to %s artifact '%s' in bucket '%s': %s", httpMethod.name().toLowerCase(), objectKey, bucketName, awsException.getMessage() ), awsException); } }
Example #3
Source File: S3RegionCorrector.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 6 votes |
public static Map<String, String> correctRegion(@NotNull final String bucketName, @NotNull final Map<String, String> storageSettings) { if (TeamCityProperties.getBooleanOrTrue("teamcity.internal.storage.s3.autoCorrectRegion")) { final String initialRegion = storageSettings.get(REGION_NAME_PARAM); final String correctedRegion = IOGuard.allowNetworkCall(() -> { try { return withS3Client(storageSettings, s3Client -> withClientCorrectingRegion(s3Client, storageSettings, client -> getRegionName(client.getBucketLocation(bucketName)))); } catch (Throwable t) { throw new RuntimeException(t); } }); if (!correctedRegion.equalsIgnoreCase(initialRegion)) { final HashMap<String, String> correctedSettings = new HashMap<>(storageSettings); correctedSettings.put(REGION_NAME_PARAM, correctedRegion); LOGGER.debug(() -> "Bucket [" + bucketName + "] location is corrected: [" + initialRegion + "] -> [" + correctedRegion + "]"); return correctedSettings; } } return storageSettings; }
Example #4
Source File: VmwareCloudImage.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
private void cleanupOldInstances() { final long stoppedOrphanedTimeout = TeamCityProperties.getLong("teamcity.vmware.stopped.orphaned.timeout", STOPPED_ORPHANED_TIMEOUT); final Date considerTime = new Date(System.currentTimeMillis() - stoppedOrphanedTimeout); processStoppedInstances(new Function<VmwareInstance, Boolean>() { public Boolean fun(final VmwareInstance vmInstance) { final String vmName = vmInstance.getName(); final VmwareCloudInstance instance = findInstanceById(vmName); if (instance != null && instance.getStatusUpdateTime().before(considerTime)){ LOG.info(String.format("VM %s was orphaned and will be deleted", vmName)); deleteInstance(instance); return true; } return false; } }); }
Example #5
Source File: KubeCloudClient.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@Override public void terminateInstance(@NotNull CloudInstance cloudInstance) { final KubeCloudInstance kubeCloudInstance = (KubeCloudInstance) cloudInstance; kubeCloudInstance.setStatus(InstanceStatus.SCHEDULED_TO_STOP); myExecutorService.submit(() -> { long gracePeriod = TeamCityProperties.getLong(TEAMCITY_KUBE_PODS_GRACE_PERIOD, 0); kubeCloudInstance.setStatus(InstanceStatus.STOPPING); try{ int failedDeleteAttempts = 0; final String pvcName = kubeCloudInstance.getPVCName(); while (!myApiConnector.deletePod(kubeCloudInstance.getName(), gracePeriod)){ failedDeleteAttempts++; if(failedDeleteAttempts == 3) throw new KubeCloudException("Failed to delete pod " + kubeCloudInstance.getName()); } failedDeleteAttempts = 0; while (pvcName != null && !myApiConnector.deletePVC(pvcName)){ failedDeleteAttempts++; if(failedDeleteAttempts == 3) throw new KubeCloudException("Failed to delete PersistentVolumeClaim " + pvcName); } kubeCloudInstance.setError(null); kubeCloudInstance.setStatus(InstanceStatus.STOPPED); } catch (KubernetesClientException ex){ kubeCloudInstance.setStatus(InstanceStatus.ERROR); kubeCloudInstance.setError(new CloudErrorInfo("Failed to terminate instance", ex.getMessage(), ex)); } kubeCloudInstance.getImage().populateInstances(); }); }
Example #6
Source File: S3SignedUrlFileUploader.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 5 votes |
@NotNull private HttpConnectionManager createMultiThreadedHttpConnectionManager(final int connectionTimeout) { final HttpConnectionManager threadSafeConnectionManager = HttpUtil.createMultiThreadedHttpConnectionManager(connectionTimeout); final int maxConnections = TeamCityProperties.getInteger("teamcity.s3.artifactUploader.maxTotalConnections", DEFAULT_TOTAL_CONNECTIONS); threadSafeConnectionManager.getParams().setMaxTotalConnections(maxConnections); threadSafeConnectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnections); return threadSafeConnectionManager; }
Example #7
Source File: S3Util.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 5 votes |
@Nullable private static String extractCorrectedRegion(@NotNull final Throwable e) { @Nullable final AmazonS3Exception awsException = e instanceof AmazonS3Exception ? (AmazonS3Exception)e : ExceptionUtil.getCause(e, AmazonS3Exception.class); if (awsException != null && TeamCityProperties.getBooleanOrTrue("teamcity.internal.storage.s3.autoCorrectRegion") && awsException.getAdditionalDetails() != null) { final String correctRegion = awsException.getAdditionalDetails().get("Region"); if (correctRegion != null) { return correctRegion; } else { return awsException.getAdditionalDetails().get("x-amz-bucket-region"); } } else { return null; } }
Example #8
Source File: SmbDeployerRunner.java From teamcity-deployer-plugin with Apache License 2.0 | 5 votes |
private boolean shouldEnforceSMBv1(@NotNull final BuildRunnerContext context) { boolean shouldEnforceOnBuild = StringUtil.isTrue(context.getBuild().getSharedConfigParameters().get(SMBRunnerConstants.SHOULD_ENFORCE_SMB1)); if (shouldEnforceOnBuild) { return true; } return TeamCityProperties.getBoolean(SMBRunnerConstants.SHOULD_ENFORCE_SMB1); }
Example #9
Source File: VMWarePropertiesReader.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
@Nullable private static String getToolPath(@NotNull final BuildAgentConfiguration configuration) { final String rpctoolPath = TeamCityProperties.getProperty(RPC_TOOL_PARAMETER); if (StringUtil.isNotEmpty(rpctoolPath)){ return rpctoolPath; } if (SystemInfo.isUnix) { // Linux, MacOSX, FreeBSD final Map<String, String> envs = configuration.getBuildParameters().getEnvironmentVariables(); final String path = envs.get("PATH"); if (path != null) for (String p : StringUtil.splitHonorQuotes(path, File.pathSeparatorChar)) { final File file = new File(p, VMWARE_RPCTOOL_NAME); if (file.exists()) { return file.getAbsolutePath(); } } } if (SystemInfo.isLinux) { return getExistingCommandPath(LINUX_COMMANDS); } else if (SystemInfo.isWindows) { return getExistingCommandPath(WINDOWS_COMMANDS); } else if (SystemInfo.isMac) { return getExistingCommandPath(MAC_COMMANDS); } else { return getExistingCommandPath(LINUX_COMMANDS); //todo: update for other OS'es } }
Example #10
Source File: CloudAsyncTaskExecutor.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
public CloudAsyncTaskExecutor(String prefix) { myPrefix = prefix; myExecutingTasks = new ConcurrentHashMap<AsyncCloudTask, TaskCallbackHandler>(); int threadCount = TeamCityProperties.getInteger("teamcity.vmware.profile.async.threads", 2); myExecuteAllAsync = threadCount > 1; myExecutor = ExecutorsFactory.newFixedScheduledDaemonExecutor(prefix, threadCount); scheduleWithFixedDelay("Check for tasks", new Runnable() { public void run() { checkTasks(); } }, 0, 300, TimeUnit.MILLISECONDS); }
Example #11
Source File: FakeVirtualMachine.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
@Override public void shutdownGuest() throws RemoteException { FakeModel.instance().publishEvent(getName(), "shutdownGuest"); if (myGuestInfo != null) { FAKE_MODEL_THREAD_FACTORY.newThread(() -> { try { Thread.sleep(TeamCityProperties.getIntervalMilliseconds("test.guest.shutdown.sleep.interval", GUEST_SHUTDOWN_SLEEP_INTERVAL)); updateVersion(); myIsStarted.set(false); } catch (InterruptedException e) {} }).start(); } else { throw new RemoteException("no guest tools available"); } }
Example #12
Source File: VmwareCloudImage.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public synchronized CanStartNewInstanceResult canStartNewInstanceWithDetails() { if (getErrorInfo() != null){ LOG.debug("Can't start new instance, if image is erroneous"); return CanStartNewInstanceResult.no("Image is erroneous."); } final String sourceId = myImageDetails.getSourceId(); if (myImageDetails.getBehaviour().isUseOriginal()) { final VmwareCloudInstance myInstance = findInstanceById(sourceId); if (myInstance == null) { return CanStartNewInstanceResult.no("Can't find original instance by id " + sourceId); } if (myInstance.getStatus() == InstanceStatus.STOPPED) { return CanStartNewInstanceResult.yes(); } return CanStartNewInstanceResult.no("Original instance with id " + sourceId + " is not being stopped"); } final boolean countStoppedVmsInLimit = TeamCityProperties.getBoolean(VmwareConstants.CONSIDER_STOPPED_VMS_LIMIT) && myImageDetails.getBehaviour().isDeleteAfterStop(); final List<String> consideredInstances = new ArrayList<String>(); for (VmwareCloudInstance instance : getInstances()) { if (instance.getStatus() != InstanceStatus.STOPPED || countStoppedVmsInLimit) consideredInstances.add(instance.getInstanceId()); } final boolean canStartMore = consideredInstances.size() < myImageDetails.getMaxInstances(); final String message = String.format("[%s] Instances count: %d %s, can start more: %s", sourceId, consideredInstances.size(), Arrays.toString(consideredInstances.toArray()), String.valueOf(canStartMore)); LOG.debug(message); return canStartMore ? CanStartNewInstanceResult.yes() : CanStartNewInstanceResult.no("Image instance limit exceeded"); }
Example #13
Source File: FakeVirtualMachine.java From teamcity-vmware-plugin with Apache License 2.0 | 5 votes |
@Override public Task powerOffVM_Task() throws RemoteException { FakeModel.instance().publishEvent(getName(), "powerOffVM_Task"); if (!myIsStarted.get()){ throw new RemoteException("Already stopped"); } final TaskInfo taskInfo = new TaskInfo(); final Thread thread = FAKE_MODEL_THREAD_FACTORY.newThread(() -> { try { taskInfo.setState(TaskInfoState.running); Thread.sleep(TeamCityProperties.getIntervalMilliseconds("test.force.shutdown.sleep.interval", FORCE_SHUTDOWN_SLEEP_INTERVAL)); updateVersion(); myIsStarted.set(false); taskInfo.setState(TaskInfoState.success); } catch (InterruptedException e) { } }); thread.start(); return new Task(null, null){ @Override public TaskInfo getTaskInfo() throws InvalidProperty, RuntimeFault, RemoteException { return taskInfo; } @Override public String waitForTask() throws RuntimeFault, RemoteException, InterruptedException { thread.join(); return taskInfo.getState().name(); } }; }
Example #14
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
private VMWareCloudClient recreateClient(final VMWareCloudClient oldClient, final CloudClientParameters parameters, boolean waitForInitialization){ final long updateTime = TeamCityProperties.getLong("teamcity.vsphere.instance.status.update.delay.ms", 250); return recreateClient(oldClient, parameters, updateTime, waitForInitialization); }
Example #15
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
private VMWareCloudClient recreateClient(final VMWareCloudClient oldClient, final CloudClientParameters parameters){ final long updateTime = TeamCityProperties.getLong("teamcity.vsphere.instance.status.update.delay.ms", 250); return recreateClient(oldClient, parameters, updateTime, true); }
Example #16
Source File: VmwareCloudIntegrationTest.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
private void recreateClient(){ recreateClient(TeamCityProperties.getLong("teamcity.vsphere.instance.status.update.delay.ms", 250)); }
Example #17
Source File: VMWareApiConnectorImpl.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
private static long getGuestShutdownTimeout() { return TeamCityProperties.getIntervalMilliseconds("teamcity.vmware.guest.shutdown.timeout", GUEST_SHUTDOWN_TIMEOUT); }
Example #18
Source File: VMWareApiConnectorImpl.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
private static long getCheckInstanceStatusDelay() { return TeamCityProperties.getIntervalMilliseconds("teamcity.vmware.instance.status.check.delay", 5000); }
Example #19
Source File: S3PreSignedUrlProviderImpl.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 4 votes |
@Override public int getUrlLifetimeSec() { return TeamCityProperties.getInteger(S3Constants.S3_URL_LIFETIME_SEC, S3Constants.DEFAULT_S3_URL_LIFETIME_SEC); }
Example #20
Source File: KubeBackgroundUpdaterImpl.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
public KubeBackgroundUpdaterImpl(@NotNull ExecutorServices executorServices) { long delay = TeamCityProperties.getLong(KUBE_POD_MONITORING_PERIOD, 60); executorServices.getNormalExecutorService().scheduleWithFixedDelay(this::populateInstances, delay, delay, TimeUnit.SECONDS); }