use of jetbrains.buildServer.server.rest.errors.InvalidStateException in project teamcity-rest by JetBrains.
the class Property method getAllowedValues.
@NotNull
private static List<String> getAllowedValues() {
// allow empty values by default
String valuesLocatorText = TeamCityProperties.getPropertyOrNull("rest.listSecureProperties.valuesLocator", "password:()");
try {
if (!StringUtil.isEmpty(valuesLocatorText)) {
Locator valuesLocator = new Locator(valuesLocatorText, "password", "enabled");
Boolean enabled = valuesLocator.getSingleDimensionValueAsBoolean("enabled", true);
if (enabled != null && !enabled) {
return Collections.emptyList();
}
List<String> values = valuesLocator.getDimensionValue("password");
valuesLocator.checkLocatorFullyProcessed();
return values;
}
} catch (LocatorProcessException e) {
throw new InvalidStateException("Wrong '" + "rest.listSecureProperties.valuesLocator" + "' server internal property value, remove it or use format 'password:(),password:(sample)', error: " + e.getMessage());
}
return Collections.emptyList();
}
use of jetbrains.buildServer.server.rest.errors.InvalidStateException in project teamcity-rest by JetBrains.
the class CloudRequest method stopInstance.
@DELETE
@Path("/instances/{instanceLocator}")
@ApiOperation(value = "Stop cloud instance matching the locator.", nickname = "stopInstance")
public void stopInstance(@PathParam("instanceLocator") String instanceLocator) {
jetbrains.buildServer.clouds.CloudInstance instance = myCloudInstanceFinder.getItem(instanceLocator).getInstance();
final SUser user = myServiceLocator.getSingletonService(UserFinder.class).getCurrentUser();
CloudUtil cloudUtil = myBeanContext.getSingletonService(CloudUtil.class);
String profileId = cloudUtil.getProfileId(instance.getImage());
if (profileId == null) {
throw new InvalidStateException("Cannot find profile for the cloud image");
}
myBeanContext.getSingletonService(CloudManager.class).terminateInstance(profileId, instance.getImageId(), instance.getInstanceId(), TerminateInstanceReason.userAction(user));
}
use of jetbrains.buildServer.server.rest.errors.InvalidStateException in project teamcity-rest by JetBrains.
the class CloudInstance method startInstance.
@Nullable
public jetbrains.buildServer.clouds.CloudInstance startInstance(@NotNull final SUser user, @NotNull final ServiceLocator serviceLocator) {
if (submittedImage == null) {
throw new BadRequestException("Cloud Instance should contain image");
}
CloudUtil util = serviceLocator.getSingletonService(CloudUtil.class);
jetbrains.buildServer.clouds.CloudImage image = submittedImage.getFromPosted(serviceLocator);
String profileId = util.getProfileId(image);
if (profileId == null) {
throw new InvalidStateException("Cannot find profile for the cloud image");
}
CloudManager cloudManager = serviceLocator.getSingletonService(CloudManager.class);
cloudManager.startInstance(profileId, image.getId(), StartInstanceReason.userAction(user));
return null;
}
use of jetbrains.buildServer.server.rest.errors.InvalidStateException in project teamcity-rest by JetBrains.
the class ServerRequest method startBackup.
/**
* @param fileName relative file name to save backup to (will be saved into
* the default backup directory (<tt>.BuildServer/backup</tt>
* if not overriden in main-config.xml)
* @param addTimestamp whether to add timestamp to the file or not
* @param includeConfigs whether to include configs into the backup or not
* @param includeDatabase whether to include database into the backup or not
* @param includeBuildLogs whether to include build logs into the backup or not
* @param includePersonalChanges whether to include personal changes into the backup or not
* @return the resulting file name that the backup will be saved to
*/
@POST
@Path("/backup")
@Produces({ "text/plain" })
@ApiOperation(value = "Start a new backup.", nickname = "startBackup")
public String startBackup(@QueryParam("fileName") String fileName, @QueryParam("addTimestamp") Boolean addTimestamp, @QueryParam("includeConfigs") Boolean includeConfigs, @QueryParam("includeDatabase") Boolean includeDatabase, @QueryParam("includeBuildLogs") Boolean includeBuildLogs, @QueryParam("includePersonalChanges") Boolean includePersonalChanges, @QueryParam("includeRunningBuilds") Boolean includeRunningBuilds, @QueryParam("includeSupplimentaryData") Boolean includeSupplimentaryData) {
BackupProcessManager backupManager = myServiceLocator.getSingletonService(BackupProcessManager.class);
BackupConfig backupConfig = new BackupConfig();
if (StringUtil.isNotEmpty(fileName)) {
if (!TeamCityProperties.getBoolean("rest.request.server.backup.allowAnyTargetPath")) {
File backupDir = new File(myDataProvider.getBean(ServerPaths.class).getBackupDir());
try {
FileSecurityUtil.checkInsideDirectory(FileUtil.resolvePath(backupDir, fileName), backupDir);
} catch (Exception e) {
// the message contains absolute paths
if (myPermissionChecker.hasGlobalPermission(Permission.MANAGE_SERVER_INSTALLATION)) {
throw e;
}
throw new BadRequestException("Target file name (" + fileName + ") should be relative path.", null);
}
}
if (addTimestamp != null) {
backupConfig.setFileName(fileName, addTimestamp);
} else {
backupConfig.setFileName(fileName);
}
} else {
throw new BadRequestException("No target file name specified.", null);
}
if (includeConfigs != null)
backupConfig.setIncludeConfiguration(includeConfigs);
if (includeDatabase != null)
backupConfig.setIncludeDatabase(includeDatabase);
if (includeBuildLogs != null)
backupConfig.setIncludeBuildLogs(includeBuildLogs);
if (includePersonalChanges != null)
backupConfig.setIncludePersonalChanges(includePersonalChanges);
if (includeRunningBuilds != null)
backupConfig.setIncludeRunningBuilds(includeRunningBuilds);
if (includeSupplimentaryData != null)
backupConfig.setIncludeSupplementaryData(includeSupplimentaryData);
try {
backupManager.startBackup(backupConfig);
} catch (MaintenanceProcessAlreadyRunningException e) {
throw new InvalidStateException("Cannot start backup because another maintenance process is in progress", e);
}
return backupConfig.getResultFileName();
}
Aggregations