Search in sources :

Example 1 with DefaultLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult in project gocd by gocd.

the class ValueStreamMapPerformanceTest method shouldTestVSMForMeshInUpstreamAndDownstream.

@Test(timeout = 240000)
@RunIf(value = DatabaseChecker.class, arguments = { DatabaseChecker.H2 })
public void shouldTestVSMForMeshInUpstreamAndDownstream() throws Exception {
    int numberOfNodesPerLevel = 5;
    int numberOfLevels = 5;
    int numberOfInstancesForUpstream = 1;
    int numberOfInstancesForDownstream = 10;
    ScmMaterial svn = u.wf((ScmMaterial) MaterialsMother.defaultMaterials().get(0), "folder1");
    String[] svn_revs = { "svn_1" };
    u.checkinInOrder(svn, svn_revs);
    PipelineConfig upstreamConfig = graphGenerator.createPipelineWithInstances("upstream", new ArrayList<>(), 1);
    PipelineConfig currentConfig = graphGenerator.createMesh(upstreamConfig, "current", "up", numberOfInstancesForUpstream, numberOfNodesPerLevel, numberOfLevels);
    graphGenerator.createMesh(currentConfig, "downstream", "down", numberOfInstancesForDownstream, numberOfNodesPerLevel, numberOfLevels);
    long start = System.currentTimeMillis();
    DefaultLocalizedOperationResult result = new DefaultLocalizedOperationResult();
    ValueStreamMapPresentationModel presentationModel = valueStreamMapService.getValueStreamMap("current", 1, Username.ANONYMOUS, result);
    long timeTaken = (System.currentTimeMillis() - start) / 1000;
    assertThat(String.format("VSM took %ds. Should have been generated in 30s.", timeTaken), timeTaken, Matchers.lessThan(30l));
    assertThat(result.isSuccessful(), is(true));
    assertThat(presentationModel.getNodesAtEachLevel().size(), is(14));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 2 with DefaultLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult in project gocd by gocd.

the class PipelineConfigServiceIntegrationTest method shouldNotifyListenersWithPreprocessedConfigUponSuccessfulUpdate.

@Test
public void shouldNotifyListenersWithPreprocessedConfigUponSuccessfulUpdate() {
    final String pipelineName = UUID.randomUUID().toString();
    final String templateName = UUID.randomUUID().toString();
    final boolean[] listenerInvoked = { false };
    setupPipelineWithTemplate(pipelineName, templateName);
    PipelineConfig pipelineConfig1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
    String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig1);
    String md5 = CachedDigestUtils.md5Hex(xml);
    EntityConfigChangedListener<PipelineConfig> pipelineConfigChangedListener = new EntityConfigChangedListener<PipelineConfig>() {

        @Override
        public void onConfigChange(CruiseConfig newCruiseConfig) {
        }

        @Override
        public void onEntityConfigChange(PipelineConfig pipelineConfig) {
            listenerInvoked[0] = true;
            assertThat(pipelineConfig.first(), is(goConfigService.cruiseConfig().getTemplateByName(new CaseInsensitiveString(templateName)).first()));
        }
    };
    goConfigService.register(pipelineConfigChangedListener);
    PipelineConfig pipeline = PipelineConfigMother.pipelineConfigWithTemplate(pipelineName, templateName);
    pipeline.setVariables(new EnvironmentVariablesConfig());
    pipelineConfigService.updatePipelineConfig(user, pipeline, md5, new DefaultLocalizedOperationResult());
    assertThat(listenerInvoked[0], is(true));
}
Also used : DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener)

Example 3 with DefaultLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult in project gocd by gocd.

the class PipelineConfigServiceIntegrationTest method shouldNotifyListenersWithPreprocessedConfigUponSuccessfulCreate.

@Test
public void shouldNotifyListenersWithPreprocessedConfigUponSuccessfulCreate() {
    final String pipelineName = UUID.randomUUID().toString();
    final String templateName = UUID.randomUUID().toString();
    final boolean[] listenerInvoked = { false };
    setupPipelineWithTemplate(pipelineName, templateName);
    EntityConfigChangedListener<PipelineConfig> pipelineConfigChangedListener = new EntityConfigChangedListener<PipelineConfig>() {

        @Override
        public void onConfigChange(CruiseConfig newCruiseConfig) {
        }

        @Override
        public void onEntityConfigChange(PipelineConfig pipelineConfig) {
            listenerInvoked[0] = true;
            assertThat(pipelineConfig.first(), is(goConfigService.cruiseConfig().getTemplateByName(new CaseInsensitiveString(templateName)).first()));
        }
    };
    goConfigService.register(pipelineConfigChangedListener);
    PipelineConfig pipeline = PipelineConfigMother.pipelineConfigWithTemplate(UUID.randomUUID().toString(), templateName);
    pipeline.setVariables(new EnvironmentVariablesConfig());
    pipelineConfigService.createPipelineConfig(user, pipeline, new DefaultLocalizedOperationResult(), "group1");
    assertThat(listenerInvoked[0], is(true));
}
Also used : DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener)

Example 4 with DefaultLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult in project gocd by gocd.

the class ScheduleService method cancelAndTriggerRelevantStages.

// synchronized for updating job
public Stage cancelAndTriggerRelevantStages(Long stageId, Username username, LocalizedOperationResult result) throws Exception {
    Stage stageForId;
    LocalizedOperationResult opResult = result == null ? new DefaultLocalizedOperationResult() : result;
    try {
        stageForId = stageService.stageById(stageId);
    } catch (Exception e) {
        LOGGER.error("[Stage Cancellation] Failed to retrieve stage identifier", e);
        opResult.notFound(LocalizedMessage.string("STAGE_FOR_LOCATOR_NOT_FOUND", stageId), HealthStateType.general(HealthStateScope.GLOBAL));
        return null;
    }
    if (!stageForId.isActive()) {
        opResult.setMessage(LocalizedMessage.string("STAGE_IS_NOT_ACTIVE_FOR_CANCELLATION"));
        return stageForId;
    }
    String stageMutex = mutexForStageInstance(stageForId.getIdentifier());
    synchronized (stageMutex) {
        // reload stage so we see committed state after acquiring mutex
        final Stage stage = stageService.stageById(stageId);
        String pipelineName = stage.getIdentifier().getPipelineName();
        String stageName = stage.getIdentifier().getStageName();
        String user = username == null ? null : username.getUsername().toString();
        if (!securityService.hasOperatePermissionForStage(pipelineName, stageName, user)) {
            opResult.unauthorized(LocalizedMessage.string("UNAUTHORIZED_TO_OPERATE_STAGE", stageName), HealthStateType.unauthorised());
            return null;
        }
        LOGGER.info("[Stage Cancellation] Cancelling stage " + stage.getIdentifier());
        transactionTemplate.executeWithExceptionHandling(new com.thoughtworks.go.server.transaction.TransactionCallbackWithoutResult() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {
                stageService.cancelStage(stage);
            }
        });
        transactionTemplate.executeWithExceptionHandling(new com.thoughtworks.go.server.transaction.TransactionCallbackWithoutResult() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {
                automaticallyTriggerRelevantStagesFollowingCompletionOf(stage);
            }
        });
        opResult.setMessage(LocalizedMessage.string("STAGE_CANCELLED_SUCCESSFULLY"));
        return stage;
    }
}
Also used : DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) TransactionStatus(org.springframework.transaction.TransactionStatus) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) InvalidAgentException(com.thoughtworks.go.remote.work.InvalidAgentException)

Example 5 with DefaultLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldFailWhenTryingToAddPipelineWithTheSameNameAsAnotherPipelineDefinedRemotely_EntitySave.

@Test
public void shouldFailWhenTryingToAddPipelineWithTheSameNameAsAnotherPipelineDefinedRemotely_EntitySave() throws Exception {
    assertThat(configWatchList.getCurrentConfigRepos().size(), is(1));
    repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestCommit);
    assertThat(cachedGoConfig.currentConfig().hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true));
    PipelineConfig dupPipelineConfig = PipelineMother.twoBuildPlansWithResourcesAndSvnMaterialsAtUrl("pipe1", "ut", "www.spring.com");
    try {
        goConfigDao.updateConfig(new CreatePipelineConfigCommand(goConfigService, dupPipelineConfig, Username.ANONYMOUS, new DefaultLocalizedOperationResult(), "default"), Username.ANONYMOUS);
        fail("Should have thrown");
    } catch (RuntimeException ex) {
        PipelineConfig pipe1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString("pipe1"));
        String errorMessage = dupPipelineConfig.errors().on(PipelineConfig.NAME);
        assertThat(errorMessage, containsString("You have defined multiple pipelines named 'pipe1'. Pipeline names must be unique. Source(s):"));
        Matcher matcher = Pattern.compile("^.*\\[(.*),\\s(.*)\\].*$").matcher(errorMessage);
        assertThat(matcher.matches(), is(true));
        assertThat(matcher.groupCount(), is(2));
        List<String> expectedSources = asList(dupPipelineConfig.getOriginDisplayName(), pipe1.getOriginDisplayName());
        List<String> actualSources = new ArrayList<>();
        for (int i = 1; i <= matcher.groupCount(); i++) {
            actualSources.add(matcher.group(i));
        }
        assertThat(actualSources.size(), is(expectedSources.size()));
        assertThat(actualSources.containsAll(expectedSources), is(true));
    }
}
Also used : CreatePipelineConfigCommand(com.thoughtworks.go.config.update.CreatePipelineConfigCommand) Matcher(java.util.regex.Matcher) DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) StringContains.containsString(org.hamcrest.core.StringContains.containsString)

Aggregations

DefaultLocalizedOperationResult (com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult)5 EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)2 RunIf (com.googlecode.junit.ext.RunIf)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 CreatePipelineConfigCommand (com.thoughtworks.go.config.update.CreatePipelineConfigCommand)1 InvalidAgentException (com.thoughtworks.go.remote.work.InvalidAgentException)1 GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)1 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)1 LocalizedOperationResult (com.thoughtworks.go.server.service.result.LocalizedOperationResult)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1