Search in sources :

Example 1 with MaterialInfo

use of com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo 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 2 with MaterialInfo

use of com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo 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)

Aggregations

MaterialInfo (com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo)2 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)2 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 ServerHealthStates (com.thoughtworks.go.serverhealth.ServerHealthStates)2 ApiController (com.thoughtworks.go.api.ApiController)1 ApiVersion (com.thoughtworks.go.api.ApiVersion)1 ApiAuthenticationHelper (com.thoughtworks.go.api.spring.ApiAuthenticationHelper)1 MessageJson (com.thoughtworks.go.api.util.MessageJson)1 MaterialWithModificationsRepresenter (com.thoughtworks.go.apiv1.internalmaterials.representers.MaterialWithModificationsRepresenter)1 UsagesRepresenter (com.thoughtworks.go.apiv1.internalmaterials.representers.UsagesRepresenter)1 Material (com.thoughtworks.go.domain.materials.Material)1 MaterialUpdateService (com.thoughtworks.go.server.materials.MaterialUpdateService)1 MaintenanceModeService (com.thoughtworks.go.server.service.MaintenanceModeService)1 MaterialConfigConverter (com.thoughtworks.go.server.service.MaterialConfigConverter)1 MaterialConfigService (com.thoughtworks.go.server.service.MaterialConfigService)1 MaterialService (com.thoughtworks.go.server.service.MaterialService)1 HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)1