Skip to content

yandex-devtools commits during 1,5 of using this plugin #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TEAMCITY_VERSION=10.0.3


all:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a real interest adding a Makefile for the build process ?


tsinstall:
apt-get install teamcity-server

deps:
mvn install:install-file -Dfile=/usr/local/teamcity-10.0.3/webapps/ROOT/WEB-INF/lib/cloud-interface.jar -DgroupId=jetbrains.buildServer.clouds -DartifactId=cloud-interface -Dversion=10.0.3 -Dpackaging=jar
mvn install:install-file -Dfile=/usr/local/teamcity-10.0.3/webapps/ROOT/WEB-INF/lib/cloud-shared.jar -DgroupId=jetbrains.buildServer.clouds -DartifactId=cloud-shared -Dversion=10.0.3 -Dpackaging=jar

pure_build:
mvn clean package

build: tsinstall deps pure_build
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


public class OpenstackAgentProperties extends AgentLifeCycleAdapter {
public class OpenstackAgentPropertiesReader extends AgentLifeCycleAdapter {
@NotNull private static final Logger LOG = Loggers.AGENT;
@NotNull private final String metadataUrl = "http://169.254.169.254/openstack/latest/meta_data.json";
@NotNull private final BuildAgentConfigurationEx agentConfiguration;

public OpenstackAgentProperties(@NotNull final BuildAgentConfigurationEx agentConfiguration, @NotNull EventDispatcher<AgentLifeCycleAdapter> dispatcher) {
public OpenstackAgentPropertiesReader(@NotNull final BuildAgentConfigurationEx agentConfiguration, @NotNull EventDispatcher<AgentLifeCycleAdapter> dispatcher) {
this.agentConfiguration = agentConfiguration;
dispatcher.addListener(this);
}
Expand All @@ -41,6 +42,23 @@ public void afterAgentConfigurationLoaded(@NotNull BuildAgent agent) {

JsonElement metadataElement = new JsonParser().parse(rawMetadata);

JsonElement teamCityUserData = metadataElement.getAsJsonObject().get("meta");
Type type = new TypeToken<HashMap<String, String>>() {}.getType();
HashMap<String,String> customParameters = new Gson().fromJson(teamCityUserData, type);

if (!customParameters.containsKey(OpenstackCloudParameters.SERVER_URL)) {
LOG.info("Not my OpenStack instance, skipping");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal to configure URL & name of TeamCity server ? This informations are provided by cloud process. If it is to use an Openstack agent as classic agent, is it duplicate of #23 ?

return;
}

for (Map.Entry<String, String> entry : customParameters.entrySet()) {
if (Objects.equals(entry.getKey(), OpenstackCloudParameters.SERVER_URL)) {
agentConfiguration.setServerUrl(entry.getValue());
} else {
agentConfiguration.addConfigurationParameter(entry.getKey(), entry.getValue());
}
}

String uuid = metadataElement.getAsJsonObject().get("uuid").getAsString();
if (uuid != null) {
LOG.info(String.format("Setting %s to %s", OpenstackCloudParameters.OPENSTACK_INSTANCE_ID, uuid));
Expand All @@ -49,17 +67,9 @@ public void afterAgentConfigurationLoaded(@NotNull BuildAgent agent) {

String name = metadataElement.getAsJsonObject().get("name").getAsString();
if (name != null) {
LOG.info(String.format("Setting name to %s", name));
agentConfiguration.setName(name);
}

JsonElement teamCityUserData = metadataElement.getAsJsonObject().get("meta");
Type type = new TypeToken<HashMap<String, String>>() {}.getType();
HashMap<String,String> customParameters = new Gson().fromJson(teamCityUserData, type);
for (Map.Entry<String, String> entry : customParameters.entrySet()) {
agentConfiguration.addConfigurationParameter(entry.getKey(), entry.getValue());
}

LOG.info(String.format("Setting %s to %s", OpenstackCloudParameters.AGENT_CLOUD_TYPE, OpenstackCloudParameters.CLOUD_TYPE));
agentConfiguration.addConfigurationParameter(OpenstackCloudParameters.AGENT_CLOUD_TYPE, OpenstackCloudParameters.CLOUD_TYPE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-autowire="constructor">
<bean class="jetbrains.buildServer.clouds.openstack.OpenstackAgentProperties"/>
<bean class="jetbrains.buildServer.clouds.openstack.OpenstackAgentPropertiesReader"/>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public interface OpenstackCloudParameters {

String OPENSTACK_INSTANCE_ID = "agent.cloud.uuid";
String AGENT_CLOUD_TYPE = "agent.cloud.type";

String SERVER_URL = "openstack.teamcity.server_url";
String AGENT_NAME = "openstack.name";
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public CloudErrorInfo getErrorInfo() {
return errorInfo;
}

@Override
public boolean canStartNewInstance(@NotNull final CloudImage image) {
if (instanceCap == null) {
return true;
Expand All @@ -140,14 +141,17 @@ public boolean canStartNewInstance(@NotNull final CloudImage image) {
}

@NotNull
@Override
public CloudInstance startNewInstance(@NotNull final CloudImage image, @NotNull final CloudInstanceUserData data) throws QuotaException {
return ((OpenstackCloudImage)image).startNewInstance(data);
}

@Override
public void restartInstance(@NotNull final CloudInstance instance) {
((OpenstackCloudInstance)instance).restart();
}

@Override
public void terminateInstance(@NotNull final CloudInstance instance) {
((OpenstackCloudInstance)instance).terminate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import jetbrains.buildServer.serverSide.InvalidProperty;
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.ServerPaths;
import jetbrains.buildServer.util.NamedDeamonThreadFactory;
import jetbrains.buildServer.util.NamedDaemonThreadFactory;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -74,7 +74,7 @@ public OpenstackCloudClient createNewClient(@NotNull final CloudState state, @No
return new OpenstackCloudClient(params, serverPaths, new ExecutorServiceFactory() {
@NotNull
public ScheduledExecutorService createExecutorService(@NotNull final String duty) {
return Executors.newSingleThreadScheduledExecutor(new NamedDeamonThreadFactory("openstack-" + duty));
return Executors.newSingleThreadScheduledExecutor(new NamedDaemonThreadFactory("openstack-" + duty));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -78,7 +79,7 @@ public synchronized void updateStatus() {
setStatus(InstanceStatus.STOPPED);
}
} else {
LOG.debug(String.format("Will skip status updating cause instance is not created yet"));
LOG.debug("Will skip status updating cause instance is not created yet");
}
}

Expand Down Expand Up @@ -167,6 +168,13 @@ private void processError(@NotNull final Exception e) {
setStatus(InstanceStatus.ERROR);
}

private Map<String, String> getMetadata(@NotNull final CloudInstanceUserData data) {
Map<String, String> metadata = new HashMap<>();
metadata.putAll(data.getCustomAgentConfigurationParameters());
metadata.put(OpenstackCloudParameters.SERVER_URL, data.getServerAddress());
return metadata;
}

private class StartAgentCommand implements Runnable {
private final CloudInstanceUserData userData;
public StartAgentCommand(@NotNull final CloudInstanceUserData data) {
Expand All @@ -178,7 +186,7 @@ public void run() {
String openstackImageId = cloudImage.getOpenstackImageId();
String flavorId = cloudImage.getFlavorId();
CreateServerOptions options = cloudImage.getImageOptions();
options.metadata(userData.getCustomAgentConfigurationParameters());
options.metadata(getMetadata(userData));

// TODO: that code should be in OpenstackCloudImage
// but as we make it possible to change userScript
Expand Down Expand Up @@ -206,4 +214,9 @@ public void run() {
}
}
}

@Override
public String toString() {
return "OpenStackInstance(" + getName() + ")";
}
}
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<teamcity.version>10.0.3</teamcity.version>
<teamcity.version>2017.1.1</teamcity.version>
<jclouds.version>2.0.0</jclouds.version>
</properties>
<repositories>
Expand Down Expand Up @@ -67,7 +67,6 @@
<version>${teamcity.version}</version>
<scope>provided</scope>
</dependency>

</dependencies>
</dependencyManagement>
<modules>
Expand Down