Search in sources :

Example 1 with URLService

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

the class AgentUpgradeServiceTest method setUp.

@Before
public void setUp() throws Exception {
    systemEnvironment = mock(SystemEnvironment.class);
    urlService = mock(URLService.class);
    GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
    jvmExitter = mock(AgentUpgradeService.JvmExitter.class);
    agentUpgradeService = spy(new AgentUpgradeService(urlService, httpClient, systemEnvironment, jvmExitter));
    httpMethod = mock(HttpGet.class);
    doReturn(httpMethod).when(agentUpgradeService).getAgentLatestStatusGetMethod();
    closeableHttpResponse = mock(CloseableHttpResponse.class);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    when(httpClient.execute(httpMethod)).thenReturn(closeableHttpResponse);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) URLService(com.thoughtworks.go.util.URLService) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient) BasicStatusLine(org.apache.http.message.BasicStatusLine) Before(org.junit.Before)

Example 2 with URLService

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

the class DownloadFileCommandExecutor method execute.

@Override
public boolean execute(BuildCommand command, BuildSession buildSession) {
    URLService urlService = new URLService();
    String url = urlService.prefixPartialUrl(command.getStringArg("url"));
    String dest = command.getStringArg("dest");
    String src = command.getStringArg("src");
    File artifact = buildSession.resolveRelativeDir(command.getWorkingDirectory(), dest);
    FileHandler handler = new FileHandler(artifact, src);
    String checksumUrl = null;
    ChecksumFileHandler checksumFileHandler = null;
    if (command.hasArg("checksumUrl")) {
        checksumUrl = new URLService().prefixPartialUrl(command.getStringArg("checksumUrl"));
        File checksumFile;
        if (command.hasArg("checksumFile")) {
            checksumFile = buildSession.resolveRelativeDir(command.getWorkingDirectory(), command.getStringArg("checksumFile"));
        } else {
            checksumFile = TempFiles.createUniqueFile("checksum");
        }
        checksumFileHandler = new ChecksumFileHandler(checksumFile);
    }
    boolean fileExist = artifact.exists();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requesting the file [" + artifact.getAbsolutePath() + "], exist? [" + fileExist + "]");
    }
    if (fileExist && artifact.isFile()) {
        try {
            url += "?sha1=" + java.net.URLEncoder.encode(StringUtil.sha1Digest(artifact), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            LOG.error("Download error", e);
            return false;
        }
    }
    buildSession.download(handler, url, checksumFileHandler, checksumUrl);
    return true;
}
Also used : URLService(com.thoughtworks.go.util.URLService) UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File) ChecksumFileHandler(com.thoughtworks.go.domain.ChecksumFileHandler) ChecksumFileHandler(com.thoughtworks.go.domain.ChecksumFileHandler) FileHandler(com.thoughtworks.go.domain.FileHandler)

Example 3 with URLService

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

the class FetchArtifactBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    File folder = TestFileUtil.createTempFolder("log");
    File consolelog = new File(folder, "console.log");
    folder.mkdirs();
    consolelog.createNewFile();
    zip = new ZipUtil().zip(folder, TestFileUtil.createUniqueTempFile(folder.getName()), Deflater.NO_COMPRESSION);
    toClean.add(folder);
    toClean.add(zip);
    dest = new File("dest");
    dest.mkdirs();
    toClean.add(dest);
    clock = new TestingClock();
    publisher = new StubGoPublisher();
    checksumFileHandler = mock(ChecksumFileHandler.class);
    urlService = mock(URLService.class);
    downloadAction = mock(DownloadAction.class);
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) URLService(com.thoughtworks.go.util.URLService) File(java.io.File) TestingClock(com.thoughtworks.go.util.TestingClock) Before(org.junit.Before)

Example 4 with URLService

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

the class DownloadDirCommandExecutor method execute.

@Override
public boolean execute(BuildCommand command, BuildSession buildSession) {
    URLService urlService = new URLService();
    String url = urlService.prefixPartialUrl(command.getStringArg("url"));
    String dest = command.getStringArg("dest");
    String src = command.getStringArg("src");
    String checksumUrl = null;
    ChecksumFileHandler checksumFileHandler = null;
    if (command.hasArg("checksumUrl")) {
        checksumUrl = new URLService().prefixPartialUrl(command.getStringArg("checksumUrl"));
        File checksumFile;
        if (command.hasArg("checksumFile")) {
            checksumFile = buildSession.resolveRelativeDir(command.getWorkingDirectory(), command.getStringArg("checksumFile"));
        } else {
            checksumFile = TempFiles.createUniqueFile("checksum");
        }
        checksumFileHandler = new ChecksumFileHandler(checksumFile);
    }
    DirHandler handler = new DirHandler(src, buildSession.resolveRelativeDir(command.getWorkingDirectory(), dest));
    buildSession.download(handler, url, checksumFileHandler, checksumUrl);
    return true;
}
Also used : DirHandler(com.thoughtworks.go.domain.DirHandler) URLService(com.thoughtworks.go.util.URLService) ChecksumFileHandler(com.thoughtworks.go.domain.ChecksumFileHandler) File(java.io.File)

Example 5 with URLService

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

the class BuildWorkArtifactUploadingTest method shouldReportUploadFailuresWhenTheyHappen.

@Test
public void shouldReportUploadFailuresWhenTheyHappen() throws Exception {
    ArtifactPlans artifactPlans = new ArtifactPlans();
    artifactPlans.add(new ArtifactPlan("**/*.png", "mypic"));
    BuildAssignment buildAssigment = createAssignment(artifactPlans, new String[] { "logs/pic/pass.png", "logs/pic-1/pass.png" });
    BuildWork work = new BuildWork(buildAssigment);
    GoArtifactsManipulatorStub manipulator = new GoArtifactsManipulatorStub(new ArrayList<>(), new ArrayList<>(), new HttpServiceStub(), new URLService(), new ZipUtilThatRunsOutOfMemory());
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(agentIdentifier, new FakeBuildRepositoryRemote(), manipulator, environmentVariableContext, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension);
    List<UploadEntry> entries = manipulator.uploadEntries();
    assertThat(entries.isEmpty(), is(true));
    assertThat(manipulator.consoleOut(), containsString("Failed to upload [**/*.png]"));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) UploadEntry(com.thoughtworks.go.matchers.UploadEntry) URLService(com.thoughtworks.go.util.URLService) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Aggregations

URLService (com.thoughtworks.go.util.URLService)6 File (java.io.File)3 ChecksumFileHandler (com.thoughtworks.go.domain.ChecksumFileHandler)2 Before (org.junit.Before)2 GoAgentServerHttpClient (com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient)1 FakeBuildRepositoryRemote (com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote)1 DirHandler (com.thoughtworks.go.domain.DirHandler)1 FileHandler (com.thoughtworks.go.domain.FileHandler)1 UploadEntry (com.thoughtworks.go.matchers.UploadEntry)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 BuildComposer (com.thoughtworks.go.server.domain.BuildComposer)1 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 TestingClock (com.thoughtworks.go.util.TestingClock)1 ZipUtil (com.thoughtworks.go.util.ZipUtil)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicStatusLine (org.apache.http.message.BasicStatusLine)1 Test (org.junit.Test)1