Search in sources :

Example 56 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class ConsoleOutputTransmitterTest method setup.

@Before
public void setup() throws Exception {
    initMocks(this);
    // so the thread does not wake up
    new SystemEnvironment().setProperty(SystemEnvironment.INTERVAL, "60");
    requestArgumentCaptor = ArgumentCaptor.forClass(String.class);
    doNothing().when(consoleAppender).append(requestArgumentCaptor.capture());
    transmitter = new ConsoleOutputTransmitter(consoleAppender, 0, mock(ScheduledThreadPoolExecutor.class));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Before(org.junit.Before)

Example 57 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class FileValidatorTest method setUp.

@Before
public void setUp() {
    realConfigDir = new SystemEnvironment().getPropertyImpl("cruise.config.dir");
    new SystemEnvironment().setProperty("cruise.config.dir", new SystemEnvironment().getPropertyImpl("java.io.tmpdir"));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Before(org.junit.Before)

Example 58 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class SleepWork method doWork.

@Override
public void doWork(EnvironmentVariableContext environmentVariableContext, AgentWorkContext agentWorkContext) {
    cancelLatch = new CountDownLatch(1);
    agentWorkContext.getAgentRuntimeInfo().busy(new AgentBuildingInfo("sleepwork", "sleepwork1"));
    boolean canceled = false;
    DefaultGoPublisher goPublisher = new DefaultGoPublisher(agentWorkContext.getArtifactsManipulator(), new JobIdentifier(), agentWorkContext.getRepositoryRemote(), agentWorkContext.getAgentRuntimeInfo(), "utf-8");
    try {
        if (this.sleepInMilliSeconds > 0) {
            canceled = cancelLatch.await(this.sleepInMilliSeconds, TimeUnit.MILLISECONDS);
        }
        String result = canceled ? "done_canceled" : "done";
        agentWorkContext.getArtifactsManipulator().setProperty(null, new Property(name + "_result", result));
        SystemEnvironment systemEnvironment = new SystemEnvironment();
        if (systemEnvironment.isConsoleLogsThroughWebsocketEnabled() && systemEnvironment.isWebsocketsForAgentsEnabled()) {
            goPublisher.consumeLine(format("Sleeping for %s milliseconds", this.sleepInMilliSeconds));
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) CountDownLatch(java.util.concurrent.CountDownLatch) Property(com.thoughtworks.go.domain.Property)

Example 59 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class ServerConfigTest method shouldNotUpdatePasswordForMailHostIfNotChangedOrNull.

@Test
public void shouldNotUpdatePasswordForMailHostIfNotChangedOrNull() throws InvalidCipherTextException, IOException {
    File cipherFile = new SystemEnvironment().getCipherFile();
    FileUtils.deleteQuietly(cipherFile);
    FileUtils.writeStringToFile(cipherFile, "269298bc31c44620", UTF_8);
    GoCipher goCipher = new GoCipher();
    MailHost mailHost = new MailHost("abc", 12, "admin", "p", null, true, true, "anc@mail.com", "anc@mail.com", goCipher);
    ServerConfig serverConfig = new ServerConfig(null, mailHost, null, null);
    assertThat(serverConfig.mailHost().getPassword(), Is.is("p"));
    String encryptedPassword = serverConfig.mailHost().getEncryptedPassword();
    serverConfig.updateMailHost(new MailHost("abc", 12, "admin", "p", encryptedPassword, false, /* Password Not Changed */
    true, "anc@mail.com", "anc@mail.com", goCipher));
    assertThat(serverConfig.mailHost().getPassword(), Is.is("p"));
    assertThat(serverConfig.mailHost().getEncryptedPassword(), Is.is(encryptedPassword));
    serverConfig.updateMailHost(new MailHost("abc", 12, "admin", null, "", true, true, "anc@mail.com", "anc@mail.com"));
    assertThat(serverConfig.mailHost().getPassword(), Is.is(""));
    assertThat(serverConfig.mailHost().getEncryptedPassword(), Is.is(nullValue()));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GoCipher(com.thoughtworks.go.security.GoCipher) File(java.io.File) Test(org.junit.Test)

Example 60 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class ScheduledPipelineLoader method knownMaterials.

private MaterialConfigs knownMaterials(Pipeline pipeline, MaterialRevisions scheduledRevs) {
    CruiseConfig currentConfig = goConfigService.getCurrentConfig();
    MaterialConfigs configuredMaterials = new MaterialConfigs();
    for (MaterialRevision revision : scheduledRevs) {
        String fingerprint = revision.getMaterial().getFingerprint();
        // first try to find material config from current pipeline config
        MaterialConfig configuredMaterial = currentConfig.materialConfigFor(new CaseInsensitiveString(pipeline.getName()), fingerprint);
        if (configuredMaterial != null) {
            configuredMaterials.add(configuredMaterial);
            continue;
        }
        // todo: remove the global lookup fallback code after we feel safe
        if (new SystemEnvironment().get(SystemEnvironment.GO_SERVER_SCHEDULED_PIPELINE_LOADER_GLOBAL_MATERIAL_LOOKUP)) {
            // fallback to global lookup if material is not in current pipeline config (old behavior)
            configuredMaterial = currentConfig.materialConfigFor(fingerprint);
            if (configuredMaterial != null) {
                configuredMaterials.add((configuredMaterial));
            }
        }
    }
    MaterialConfigs knownMaterials = new MaterialConfigs();
    for (MaterialConfig configuredMaterial : configuredMaterials) {
        materialExpansionService.expandForScheduling(configuredMaterial, knownMaterials);
    }
    return knownMaterials;
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Aggregations

SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)174 Test (org.junit.Test)93 Before (org.junit.Before)38 File (java.io.File)37 AgentInstance (com.thoughtworks.go.domain.AgentInstance)27 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 ArrayList (java.util.ArrayList)14 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)10 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)10 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)9 AgentConfig (com.thoughtworks.go.config.AgentConfig)8 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)8 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)8 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)7 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)7 Date (java.util.Date)7 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)6