use of jetbrains.buildServer.serverSide.dependency.Dependency in project teamcity-rest by JetBrains.
the class PropEntitySnapshotDep method addTo.
@NotNull
@Override
public Dependency addTo(@NotNull final BuildTypeSettingsEx buildType, @NotNull final ServiceLocator serviceLocator) {
if (!SNAPSHOT_DEPENDENCY_TYPE_NAME.equals(type)) {
throw new BadRequestException("Snapshot dependency should have type '" + SNAPSHOT_DEPENDENCY_TYPE_NAME + "'.");
}
final Map<String, String> propertiesMap = properties == null ? Collections.emptyMap() : properties.getMap();
// compatibility mode with pre-8.0
final String buildTypeIdFromProperty = propertiesMap.get(NAME_SOURCE_BUILD_TYPE_ID);
String buildTypeIdDependOn = getBuildTypeExternalIdForDependency(sourceBuildType, buildTypeIdFromProperty, serviceLocator);
BuildTypeUtil.checkCanUseBuildTypeAsDependency(buildTypeIdDependOn, serviceLocator);
Dependency similar = getInheritedOrSameIdSimilar(buildType, serviceLocator);
if (inherited != null && inherited && similar != null) {
return similar;
}
if (similar != null && id != null && id.equals(similar.getDependOnExternalId())) {
// todo
return similar;
}
// todo: (TeamCity) for some reason API does not report adding dependency with same id. Seems like it just ignores the call
if (getSnapshotDepOrNull(buildType, buildTypeIdDependOn) != null) {
throw new BadRequestException("Snapshot dependency on build type with id '" + buildTypeIdDependOn + "' already exists.");
}
final Dependency result = serviceLocator.getSingletonService(DependencyFactory.class).createDependency(buildTypeIdDependOn);
for (Map.Entry<String, String> property : propertiesMap.entrySet()) {
if (!NAME_SOURCE_BUILD_TYPE_ID.equals(property.getKey())) {
setDependencyOption(property.getKey(), property.getValue(), result);
}
}
try {
buildType.addDependency(result);
} catch (CyclicDependencyFoundException e) {
throw new BadRequestException("Error adding dependency", e);
}
return getSnapshotDep(buildType, result.getDependOnExternalId(), serviceLocator.getSingletonService(BuildTypeFinder.class));
}
use of jetbrains.buildServer.serverSide.dependency.Dependency in project teamcity-rest by JetBrains.
the class BuildCompatibleAgentsTest method setUp.
@Override
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
setFinder(myBuildPromotionFinder);
if (!LicenseTestUtil.hasLicenseGenerator() && myServer.getLicensingPolicy().getMaxNumberOfAuthorizedAgents() < 6) {
throw new SkipException("Cannot execute test logic when there is not enough agent licenses (only works in internal dev environment tests)");
}
myProject10 = createProject("project10", "project 10");
myBt10 = myProject10.createBuildType("bt10", "bt 10");
myBt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("a", null, RequirementType.EXISTS));
myBt30 = myProject10.createBuildType("bt30", "bt 30");
myBt40 = myProject10.createBuildType("bt40", "bt 40");
myBt40.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("x", "1", RequirementType.EQUALS));
myBt50 = myProject10.createBuildType("bt50", "bt 50");
Dependency dependency = myFixture.getSingletonService(DependencyFactory.class).createDependency(myBt40);
dependency.setOption(DependencyOptions.RUN_BUILD_ON_THE_SAME_AGENT, true);
myBt50.addDependency(dependency);
// not compatible
myAgent10 = myFixture.createEnabledAgent("agent10", "Ant");
myAgent10.addConfigParameter("x", "1");
myAgent10.pushAgentTypeData();
// semi-compatible
myAgent15 = myFixture.createEnabledAgent("agent15", "Ant");
myAgent15.addConfigParameter("a", "b");
myAgent15.pushAgentTypeData();
// compatible
myAgent20 = myFixture.createEnabledAgent("agent20", "Ant");
myAgent20.addConfigParameter("a", "b");
myAgent20.addConfigParameter("x", "1");
myAgent20.pushAgentTypeData();
// compatible, but in another pool
myAgent30 = myFixture.createEnabledAgent("agent30", "Ant");
myAgent30.addConfigParameter("a", "b");
myAgent30.addConfigParameter("x", "2");
myAgent30.pushAgentTypeData();
// pool without projects
final int poolId1 = myFixture.getAgentPoolManager().createNewAgentPool("pool1").getAgentPoolId();
myFixture.getAgentPoolManager().moveAgentTypesToPool(poolId1, createSet(myAgent30.getId()));
// compatible, but excluded by policy - can only run myBt30
myAgent40 = myFixture.createEnabledAgent("agent40", "Ant");
myAgent40.addConfigParameter("a", "b");
myAgent40.addConfigParameter("x", "1");
myAgent40.pushAgentTypeData();
myFixture.getAgentTypeManager().setRunConfigurationPolicy(myAgent40.getAgentTypeId(), BuildAgentManager.RunConfigurationPolicy.SELECTED_COMPATIBLE_CONFIGURATIONS);
myFixture.getAgentTypeManager().includeRunConfigurationsToAllowed(myAgent40.getAgentTypeId(), new String[] { myBt30.getInternalId() });
myFixture.getAgentTypeManager().excludeRunConfigurationsFromAllowed(myAgent40.getAgentTypeId(), new String[] { myBt10.getInternalId() });
// compatible, but unauthorized
myAgent50 = myFixture.createEnabledAgent("agent50", "Ant");
myAgent50.addConfigParameter("a", "b");
myAgent50.addConfigParameter("x", "2");
myAgent50.pushAgentTypeData();
myAgent50.setAuthorized(false, null, "");
// compatible, but disabled
myAgent60 = myFixture.createEnabledAgent("agent60", "Ant");
myAgent60.addConfigParameter("a", "b");
myAgent60.addConfigParameter("x", "2");
myAgent60.pushAgentTypeData();
myAgent60.setEnabled(false, null, "");
// compatible, but disconnected
myAgent70 = myFixture.createEnabledAgent("agent70", "Ant");
myAgent70.addConfigParameter("a", "b");
myAgent70.addConfigParameter("x", "2");
myAgent70.pushAgentTypeData();
myAgent70.setIsAvailable(false);
myAgent70.setUnregistrationComment("comment");
myAgentManager.unregisterAgent(myAgent70.getId());
// pool without agents
myPoolId20 = myFixture.getAgentPoolManager().createNewAgentPool("pool20").getAgentPoolId();
myFixture.getAgentPoolManager().associateProjectsWithPool(myPoolId20, new HashSet<String>(Arrays.asList(String.valueOf(myProject10.getProjectId()))));
myProject20 = createProject("project20", "project 20");
myBt60 = myProject20.createBuildType("bt60", "bt 60");
// pool without agents
int poolId30 = myFixture.getAgentPoolManager().createNewAgentPool("pool30").getAgentPoolId();
myFixture.getAgentPoolManager().associateProjectsWithPool(poolId30, new HashSet<String>(Arrays.asList(String.valueOf(myProject20.getProjectId()))));
myFixture.getAgentPoolManager().dissociateProjectsFromOtherPools(poolId30, new HashSet<String>(Arrays.asList(String.valueOf(myProject20.getProjectId()))));
myBuild10 = build().in(myBt10).addToQueue().getBuildPromotion();
myBuild20 = build().in(myBt10).parameter("param1", "%x%").addToQueue().getBuildPromotion();
myBuild30 = build().in(myBt10).on(myAgent60).addToQueue().getBuildPromotion();
myBuild40 = build().in(myBt10).parameter("param1", "%abra%").addToQueue().getBuildPromotion();
final BuildCustomizer customizer = myFixture.getSingletonService(BuildCustomizerFactory.class).createBuildCustomizer(myBt10, null);
SAgentRestrictor agentRestrictor = myFixture.getSingletonService(AgentRestrictorFactory.class).createFor(AgentRestrictorType.AGENT_POOL, myPoolId20);
myBuild50 = myBt10.addToQueue(agentRestrictor, (BuildPromotionEx) customizer.createPromotion(), new TriggeredByBuilder().toString()).getBuildPromotion();
myExpected = new ExpectedCompatibilities();
myExpected.setAllBuildTypes(myBuildType, myBt10, myBt30, myBt40, myBt50, myBt60);
myExpected.setAllBuilds(myBuild10, myBuild20, myBuild30, myBuild40, myBuild50);
// should be myExpected.add(ExpectedCompatibility.agent(myBuildAgent).buildTypes(myBuildType, myBt30).builds());
// current behavior: "run on the same agent" for snapshot dep is ignored
myExpected.add(ExpectedCompatibility.agent(myBuildAgent).buildTypes(myBuildType, myBt30, myBt50).builds());
myExpected.add(ExpectedCompatibility.agent(myAgent10).buildTypes(myBuildType, myBt30, myBt40, myBt50).builds());
myExpected.add(ExpectedCompatibility.agent(myAgent15).buildTypes(myBuildType, myBt10, myBt30, myBt50).builds(myBuild10));
myExpected.add(ExpectedCompatibility.agent(myAgent20).buildTypes(myBuildType, myBt10, myBt30, myBt40, myBt50).builds(myBuild10, myBuild20));
myExpected.add(ExpectedCompatibility.agent(myAgent30).buildTypes().builds());
myExpected.add(ExpectedCompatibility.agent(myAgent40).buildTypes(myBt30).builds());
myExpected.add(ExpectedCompatibility.agent(myAgent50).buildTypes().builds());
myExpected.add(ExpectedCompatibility.agent(myAgent60).buildTypes().builds(myBuild30));
myExpected.add(ExpectedCompatibility.agent(myAgent70).buildTypes().builds());
}
use of jetbrains.buildServer.serverSide.dependency.Dependency in project teamcity-rest by JetBrains.
the class BuildTypeRequest method addSnapshotDep.
/**
* Creates new snapshot dependency. 'id' attribute is ignored in the submitted descriptor.
* Reports error if new dependency cannot be created (e.g. another dependency on the specified build configuration already exists).
*/
@POST
@Path("/{btLocator}/snapshot-dependencies")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a snapshot dependency to the matching build configuration.", nickname = "addSnapshotDependencyToBuildType")
public PropEntitySnapshotDep addSnapshotDep(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @QueryParam("fields") String fields, PropEntitySnapshotDep description) {
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
Dependency createdDependency = description.addTo(buildType.getSettingsEx(), myServiceLocator);
buildType.persist("Snapshot dependency added");
return new PropEntitySnapshotDep(createdDependency, buildType.getSettingsEx(), new Fields(fields), new BeanContext(myFactory, myServiceLocator, myApiUrlBuilder));
}
use of jetbrains.buildServer.serverSide.dependency.Dependency in project teamcity-rest by JetBrains.
the class BuildTypeRequest method replaceSnapshotDep.
@PUT
@Path("/{btLocator}/snapshot-dependencies/{snapshotDepLocator}")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update a snapshot dependency of the matching build configuration.", nickname = "replaceSnapshotDependency")
public PropEntitySnapshotDep replaceSnapshotDep(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @PathParam("snapshotDepLocator") String snapshotDepLocator, @QueryParam("fields") String fields, PropEntitySnapshotDep description) {
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
final Dependency dependency = PropEntitySnapshotDep.getSnapshotDep(buildType.get(), snapshotDepLocator, myBuildTypeFinder);
Dependency createdDependency = description.replaceIn(buildType.getSettingsEx(), dependency, myServiceLocator);
buildType.persist("Snapshot dependency replaced");
return new PropEntitySnapshotDep(createdDependency, buildType.getSettingsEx(), new Fields(fields), new BeanContext(myFactory, myServiceLocator, myApiUrlBuilder));
}
use of jetbrains.buildServer.serverSide.dependency.Dependency 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.");
}
Aggregations