Search in sources :

Example 91 with MaterialConfig

use of com.thoughtworks.go.domain.materials.MaterialConfig in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldMigrateMaterialFolderAttributeToDest.

@Test
public void shouldMigrateMaterialFolderAttributeToDest() throws Exception {
    CruiseConfig cruiseConfig = loadConfigFileWithContent(ConfigFileFixture.VERSION_2);
    MaterialConfig actual = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("multiple")).materialConfigs().first();
    assertThat(actual.getFolder(), is("part1"));
}
Also used : GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) Test(org.junit.Test)

Example 92 with MaterialConfig

use of com.thoughtworks.go.domain.materials.MaterialConfig in project gocd by gocd.

the class MaterialConnectivityServiceTest method shouldCheckConnections.

@Theory
public void shouldCheckConnections(RequestDataPoints dataPoints) throws Exception {
    MaterialConfig config = dataPoints.material.config();
    MaterialConnectivityService spy = spy(service);
    doReturn(dataPoints.klass).when(spy).getMaterialClass(dataPoints.material);
    doReturn(dataPoints.material).when(materialConfigConverter).toMaterial(config);
    ValidationBean actual = spy.checkConnection(config, executionContext);
    assertThat(actual, is(dataPoints.expectedResult));
}
Also used : MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Theory(org.junit.experimental.theories.Theory)

Example 93 with MaterialConfig

use of com.thoughtworks.go.domain.materials.MaterialConfig in project gocd by gocd.

the class InternalMaterialsControllerV1 method createMergedMap.

private Map<MaterialConfig, MaterialInfo> createMergedMap(Map<MaterialConfig, Boolean> materialConfigs, Map<String, Modification> modificationsMap, Collection<MaintenanceModeService.MaterialPerformingMDU> runningMDUs, ServerHealthStates allLogs) {
    HashMap<MaterialConfig, MaterialInfo> map = new HashMap<>();
    if (materialConfigs.isEmpty()) {
        return map;
    }
    materialConfigs.forEach((materialConfig, hasOperatePermission) -> {
        if (!materialConfig.getType().equals(DependencyMaterialConfig.TYPE)) {
            Material material = materialConfigConverter.toMaterial(materialConfig);
            List<HealthStateScope> scopes = asList(forMaterial(material), forMaterialUpdate(material), forMaterialConfig(materialConfig));
            List<ServerHealthState> logs = allLogs.stream().filter((log) -> scopes.contains(log.getType().getScope())).collect(toList());
            Modification mod = modificationsMap.getOrDefault(materialConfig.getFingerprint(), null);
            MaintenanceModeService.MaterialPerformingMDU mduInfo = runningMDUs.stream().filter((mdu) -> mdu.getMaterial().getFingerprint().equals(materialConfig.getFingerprint())).findFirst().orElse(null);
            boolean isMDUInProgress = mduInfo != null;
            Timestamp updateStartTime = isMDUInProgress ? mduInfo.getTimestamp() : null;
            map.put(materialConfig, new MaterialInfo(mod, hasOperatePermission, isMDUInProgress, updateStartTime, logs));
        }
    });
    return map;
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) MaintenanceModeService(com.thoughtworks.go.server.service.MaintenanceModeService) Material(com.thoughtworks.go.domain.materials.Material) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) Autowired(org.springframework.beans.factory.annotation.Autowired) MaterialInfo(com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo) HashMap(java.util.HashMap) MessageJson(com.thoughtworks.go.api.util.MessageJson) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) MaterialConfigService(com.thoughtworks.go.server.service.MaterialConfigService) Request(spark.Request) Arrays.asList(java.util.Arrays.asList) SparkSpringController(com.thoughtworks.go.spark.spring.SparkSpringController) Map(java.util.Map) ApiVersion(com.thoughtworks.go.api.ApiVersion) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialUpdateService(com.thoughtworks.go.server.materials.MaterialUpdateService) Routes(com.thoughtworks.go.spark.Routes) ApiController(com.thoughtworks.go.api.ApiController) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ApiAuthenticationHelper(com.thoughtworks.go.api.spring.ApiAuthenticationHelper) MaterialWithModificationsRepresenter(com.thoughtworks.go.apiv1.internalmaterials.representers.MaterialWithModificationsRepresenter) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Response(spark.Response) MaterialService(com.thoughtworks.go.server.service.MaterialService) UsagesRepresenter(com.thoughtworks.go.apiv1.internalmaterials.representers.UsagesRepresenter) Spark(spark.Spark) CachedDigestUtils.sha512_256Hex(com.thoughtworks.go.util.CachedDigestUtils.sha512_256Hex) Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) Material(com.thoughtworks.go.domain.materials.Material) MaintenanceModeService(com.thoughtworks.go.server.service.MaintenanceModeService) Timestamp(java.sql.Timestamp) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialInfo(com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 94 with MaterialConfig

use of com.thoughtworks.go.domain.materials.MaterialConfig in project gocd by gocd.

the class InternalMaterialsControllerV1 method index.

public String index(Request request, Response response) throws Exception {
    Map<MaterialConfig, Boolean> materialConfigs = materialConfigService.getMaterialConfigsWithPermissions(currentUsernameString());
    Map<String, Modification> modifications = materialService.getLatestModificationForEachMaterial();
    Collection<MaintenanceModeService.MaterialPerformingMDU> runningMDUs = maintenanceModeService.getRunningMDUs();
    ServerHealthStates logs = serverHealthService.logs();
    Map<MaterialConfig, MaterialInfo> mergedMap = createMergedMap(materialConfigs, modifications, runningMDUs, logs);
    final String etag = etagFor(mergedMap);
    if (fresh(request, etag)) {
        return notModified(response);
    }
    setEtagHeader(response, etag);
    return writerForTopLevelObject(request, response, writer -> MaterialWithModificationsRepresenter.toJSON(writer, mergedMap));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) MaterialInfo(com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo)

Example 95 with MaterialConfig

use of com.thoughtworks.go.domain.materials.MaterialConfig in project gocd by gocd.

the class InternalMaterialsControllerV1 method triggerUpdate.

public String triggerUpdate(Request request, Response response) {
    String fingerprint = request.params(FINGERPRINT);
    MaterialConfig materialConfig = materialConfigService.getMaterialConfig(currentUsernameString(), fingerprint);
    if (materialUpdateService.updateMaterial(materialConfigConverter.toMaterial(materialConfig))) {
        response.status(HttpStatus.CREATED.value());
        return MessageJson.create("OK");
    } else {
        response.status(HttpStatus.CONFLICT.value());
        return MessageJson.create("Update already in progress.");
    }
}
Also used : MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)

Aggregations

MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)171 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)90 Test (org.junit.jupiter.api.Test)86 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)74 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)64 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)48 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)44 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)42 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)42 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)39 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)36 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)20 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)19 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)19 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)17 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)13 Material (com.thoughtworks.go.domain.materials.Material)13 Modification (com.thoughtworks.go.domain.materials.Modification)13 Test (org.junit.Test)12