use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.
the class AgentPool method getAgentPoolFromPosted.
@NotNull
public jetbrains.buildServer.serverSide.agentPools.AgentPool getAgentPoolFromPosted(@NotNull final AgentPoolFinder agentPoolFinder) {
Locator resultLocator = Locator.createEmptyLocator();
boolean otherDimensionsSet = false;
if (id != null) {
otherDimensionsSet = true;
resultLocator.setDimension(AgentPoolFinder.ID.name, String.valueOf(id));
}
/*
//todo: implement this in finder!
if (name != null) {
otherDimensionsSet = true;
resultLocator.setDimension("name", name);
}
*/
if (locator != null) {
if (otherDimensionsSet) {
throw new BadRequestException("Either 'locator' or other attributes should be specified.");
}
resultLocator = new Locator(locator);
}
return agentPoolFinder.getItem(resultLocator.getStringRepresentation());
}
use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.
the class PropEntitySnapshotDep method getSnapshotDep.
public static Dependency getSnapshotDep(@NotNull final BuildTypeSettings buildType, @Nullable final String snapshotDepLocator, @NotNull final BuildTypeFinder buildTypeFinder) {
if (StringUtil.isEmpty(snapshotDepLocator)) {
throw new BadRequestException("Empty snapshot dependency locator is not supported.");
}
final Locator locator = new Locator(snapshotDepLocator, Locator.LOCATOR_SINGLE_VALUE_UNUSED_NAME, "buildType");
if (locator.isSingleValue()) {
// no dimensions found, assume it's id of the dependency (build type external id)
final String snapshotDepId = locator.getSingleValue();
// todo (TeamCity) seems like no way to get snapshot dependency by source build type
Dependency foundDependency = getSnapshotDepOrNull(buildType, snapshotDepId);
if (foundDependency != null) {
return foundDependency;
}
// fall back to internal id for compatibility
foundDependency = getSnapshotDepByInternalIdOrNull(buildType, snapshotDepId);
if (foundDependency != null) {
return foundDependency;
}
}
String buildTypeLocator = locator.getSingleDimensionValue("buildType");
if (buildTypeLocator != null) {
final String externalId = buildTypeFinder.getBuildType(null, buildTypeLocator, false).getExternalId();
final Dependency foundDependency = getSnapshotDepOrNull(buildType, externalId);
if (foundDependency != null) {
return foundDependency;
}
throw new NotFoundException("No snapshot dependency found to build type with external id '" + externalId + "'.");
}
locator.checkLocatorFullyProcessed();
throw new NotFoundException("No snapshot dependency found by locator '" + snapshotDepLocator + "'. Locator should be existing dependency source build type external id.");
}
use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.
the class TestScopeTreeCollector method prepareScopesLocator.
private Locator prepareScopesLocator(@NotNull Locator locator) {
Locator occurrencesLocator = Locator.createEmptyLocator();
occurrencesLocator.setDimension(TestOccurrenceFinder.STATUS, "FAILURE");
occurrencesLocator.setDimension(PagerData.COUNT, "-1");
occurrencesLocator.setDimension(TestOccurrenceFinder.BUILD, locator.getDimensionValue(BUILD));
occurrencesLocator.setDimension(TestOccurrenceFinder.CURRENTLY_INVESTIGATED, locator.getDimensionValue(CURRENTLY_INVESTIGATED));
occurrencesLocator.setDimension(TestOccurrenceFinder.CURRENT, locator.getDimensionValue(CURRENT));
occurrencesLocator.setDimension(TestOccurrenceFinder.AFFECTED_PROJECT, locator.getDimensionValue(AFFECTED_PROJECT));
occurrencesLocator.setDimension(TestOccurrenceFinder.NEW_FAILURE, locator.getDimensionValue(NEW_FAILURE));
occurrencesLocator.setDimension(TestOccurrenceFinder.MUTED, Locator.BOOLEAN_FALSE);
occurrencesLocator.setDimension(TestOccurrenceFinder.IGNORED, Locator.BOOLEAN_FALSE);
Locator scopesLocator = Locator.createEmptyLocator();
scopesLocator.setDimension(TestScopesCollector.TEST_OCCURRENCES, occurrencesLocator.toString());
scopesLocator.setDimension(TestScopesCollector.SCOPE_TYPE, "class");
scopesLocator.setDimension(TestScopesCollector.SPLIT_BY_BUILD_TYPE, "true");
return scopesLocator;
}
use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testBuildTypeSettings.
@Test
void testBuildTypeSettings() {
BuildTypeImpl bt10 = registerBuildType("bt10", "projectName");
bt10.setArtifactPaths("bbbb");
bt10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, false);
bt10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
bt10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_bt");
bt10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_SERVER");
bt10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 17);
final String btLocator = "id:" + bt10.getExternalId();
ParametersSubResource settingsSubResource = myBuildTypeRequest.getSettingsSubResource(btLocator);
String fields = "$long,settings($long)";
assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutDirectory", "checkout_bt"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
// default value for direct get
assertEquals("0", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
settingsSubResource.setParameter(new Property(new SimpleParameter("maximumNumberOfBuilds", "4"), false, Fields.LONG, myFixture), "$long");
assertEquals("4", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutDirectory", "checkout_bt"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("maximumNumberOfBuilds", "4"), p("shouldFailBuildIfTestsFailed", "false"));
assertEquals("5", settingsSubResource.setParameter("maximumNumberOfBuilds", new Property(new SimpleParameter("maximumNumberOfBuilds", "5"), false, Fields.LONG, myFixture), "$long").value);
assertEquals("5", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
assertEquals("6", settingsSubResource.setParameterValue("maximumNumberOfBuilds", "6"));
assertEquals("6", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
assertEquals("7", settingsSubResource.setParameterValueLong("maximumNumberOfBuilds", "7"));
assertEquals("7", settingsSubResource.getParameter("maximumNumberOfBuilds", "$long").value);
// set to default value
settingsSubResource.setParameter(new Property(new SimpleParameter("maximumNumberOfBuilds", "0"), false, Fields.LONG, myFixture), "$long");
assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutDirectory", "checkout_bt"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
settingsSubResource.deleteParameter("checkoutDirectory");
assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:any"), fields), p("allowExternalStatus", "false", true, null), p("allowPersonalBuildTriggering", "true", true, null), p("artifactRules", "bbbb", null, null), p("buildNumberCounter", "1", null, null), p("buildNumberPattern", "%build.counter%", true, null), p("checkoutDirectory", "", true, null), p("checkoutMode", "ON_SERVER", null, null), p("cleanBuild", "false", true, null), p("enableHangingBuildsDetection", "true", true, null), p("executionTimeoutMin", "17", null, null), p("maximumNumberOfBuilds", "0", true, null), p("publishArtifactCondition", "NORMALLY_FINISHED", true, null), p("shouldFailBuildIfTestsFailed", "false", null, null), p("shouldFailBuildOnAnyErrorMessage", "false", true, null), p("shouldFailBuildOnBadExitCode", "true", true, null), p("shouldFailBuildOnOOMEOrCrash", "true", true, null), p("showDependenciesChanges", "false", true, null), p("supportTestRetry", "false", true, null), p("vcsLabelingBranchFilter", "+:<default>", true, null), p("excludeDefaultBranchChanges", "false", true, null), p("buildDefaultBranch", "true", true, null), p("branchFilter", "+:*", true, null), p("generatedBuildConfigurationChecksum", "", true, null), p("buildConfigurationType", "REGULAR", true, null));
assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:true"), fields), p("allowExternalStatus", "false", true, null), p("allowPersonalBuildTriggering", "true", true, null), p("buildNumberPattern", "%build.counter%", true, null), p("checkoutDirectory", "", true, null), p("cleanBuild", "false", true, null), p("enableHangingBuildsDetection", "true", true, null), p("maximumNumberOfBuilds", "0", true, null), p("publishArtifactCondition", "NORMALLY_FINISHED", true, null), p("shouldFailBuildOnAnyErrorMessage", "false", true, null), p("shouldFailBuildOnBadExitCode", "true", true, null), p("shouldFailBuildOnOOMEOrCrash", "true", true, null), p("showDependenciesChanges", "false", true, null), p("supportTestRetry", "false", true, null), p("vcsLabelingBranchFilter", "+:<default>", true, null), p("excludeDefaultBranchChanges", "false", true, null), p("buildDefaultBranch", "true", true, null), p("branchFilter", "+:*", true, null), p("generatedBuildConfigurationChecksum", "", true, null), p("buildConfigurationType", "REGULAR", true, null));
assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:false"), fields), p("artifactRules", "bbbb", null, null), p("buildNumberCounter", "1", null, null), p("checkoutMode", "ON_SERVER", null, null), p("executionTimeoutMin", "17", null, null), p("shouldFailBuildIfTestsFailed", "false", null, null));
assertCollectionEquals("", settingsSubResource.getParameters(new Locator("defaults:false,name:buildNumberCounter"), fields), p("buildNumberCounter", "1", null, null));
HashMap<String, String> newParametersMap = new HashMap<>();
// all the same
newParametersMap.put("artifactRules", "bbbb");
newParametersMap.put("buildNumberCounter", "1");
newParametersMap.put("checkoutMode", "ON_SERVER");
newParametersMap.put("executionTimeoutMin", "17");
newParametersMap.put("shouldFailBuildIfTestsFailed", "false");
settingsSubResource.setParameters(new Properties(newParametersMap, null, new Fields("**"), getBeanContext(myFixture)), "$long");
assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("artifactRules", "bbbb"), p("buildNumberCounter", "1"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
newParametersMap.remove("artifactRules");
newParametersMap.put("buildNumberCounter", "2");
settingsSubResource.setParameters(new Properties(newParametersMap, null, new Fields("**"), getBeanContext(myFixture)), "$long");
assertCollectionEquals("", settingsSubResource.getParameters(null, fields), p("buildNumberCounter", "2"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
newParametersMap.remove("buildNumberCounter");
settingsSubResource.setParameters(new Properties(newParametersMap, null, new Fields("**"), getBeanContext(myFixture)), "$long");
assertCollectionEquals(// is reset to "1"
"", // is reset to "1"
settingsSubResource.getParameters(null, fields), // is reset to "1"
p("buildNumberCounter", "1"), p("checkoutMode", "ON_SERVER"), p("executionTimeoutMin", "17"), p("shouldFailBuildIfTestsFailed", "false"));
checkException(LocatorProcessException.class, () -> settingsSubResource.getParameters(new Locator("a:b"), "$long"), null);
checkException(BadRequestException.class, () -> settingsSubResource.setParameter(new Property(new SimpleParameter("aaa", "b"), false, Fields.LONG, myFixture), "$long"), null);
}
use of jetbrains.buildServer.server.rest.data.Locator in project teamcity-rest by JetBrains.
the class ChangeRequest method serveChanges.
// todo: use locator here, like for builds with limitLookup, changes from dependencies flag, etc.
// todo: mark changes from dependencies
/**
* Lists changes by the specified locator
* @param locator Change locator
* @param projectLocator Deprecated, use "locator" parameter instead
* @param buildTypeLocator Deprecated, use "locator" parameter instead
* @param buildLocator Deprecated, use "locator" parameter instead
* @param vcsRootInstanceLocator Deprecated, use "locator" parameter instead. Note that corresponding locator dimension is "vcsRootInstance"
* @param sinceChangeLocator Deprecated, use "locator" parameter instead
* @param start Deprecated, use "locator" parameter instead
* @param count Deprecated, use "locator" parameter instead
* @param uriInfo Deprecated, use "locator" parameter instead
* @param request Deprecated, use "locator" parameter instead
* @return
*/
@GET
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get all changes.", nickname = "getAllChanges")
public Changes serveChanges(@ApiParam(hidden = true) @QueryParam("project") String projectLocator, @ApiParam(hidden = true) @QueryParam("buildType") String buildTypeLocator, @ApiParam(hidden = true) @QueryParam("build") String buildLocator, @ApiParam(hidden = true) @QueryParam("vcsRoot") String vcsRootInstanceLocator, @ApiParam(hidden = true) @QueryParam("sinceChange") String sinceChangeLocator, @ApiParam(hidden = true) @QueryParam("start") Long start, @ApiParam(hidden = true) @QueryParam("count") Integer count, @ApiParam(format = LocatorName.CHANGE) @QueryParam("locator") String locator, @QueryParam("fields") String fields, @Context UriInfo uriInfo, @Context HttpServletRequest request) {
Locator actualLocator = locator == null ? Locator.createEmptyLocator() : new Locator(locator);
if (!actualLocator.isSingleValue()) {
updateLocatorDimension(actualLocator, "project", projectLocator);
updateLocatorDimension(actualLocator, "buildType", buildTypeLocator);
updateLocatorDimension(actualLocator, "build", buildLocator);
updateLocatorDimension(actualLocator, "vcsRootInstance", vcsRootInstanceLocator);
updateLocatorDimension(actualLocator, "sinceChange", sinceChangeLocator);
updateLocatorDimension(actualLocator, "start", start != null ? String.valueOf(start) : null);
updateLocatorDimension(actualLocator, "count", count != null ? String.valueOf(count) : null);
}
final String locatorText = actualLocator.isEmpty() ? null : actualLocator.getStringRepresentation();
PagedSearchResult<SVcsModificationOrChangeDescriptor> buildModifications = myChangeFinder.getItems(locatorText);
final UriBuilder requestUriBuilder = uriInfo.getRequestUriBuilder();
requestUriBuilder.replaceQueryParam("count", null);
requestUriBuilder.replaceQueryParam("start", null);
return new Changes(buildModifications.myEntries, new PagerData(requestUriBuilder, request.getContextPath(), buildModifications, locatorText, "locator"), new Fields(fields), myBeanContext);
}
Aggregations