use of com.thoughtworks.go.server.domain.PipelineTimeline in project gocd by gocd.
the class PipelineRepositoryIntegrationTest method shouldReturnEarliestPMRForMultipleMaterial.
@Test
public void shouldReturnEarliestPMRForMultipleMaterial() throws Exception {
final HgMaterial hgmaterial = MaterialsMother.hgMaterial("first");
final SvnMaterial svnMaterial = MaterialsMother.svnMaterial();
PipelineConfig pipelineConfig = createPipelineConfig(PIPELINE_NAME, "stage", "job");
pipelineConfig.setMaterialConfigs(new MaterialConfigs(hgmaterial.config(), svnMaterial.config()));
final DateTime date = new DateTime(1984, 12, 23, 0, 0, 0, 0);
long first = save(pipelineConfig, 1, 1.0, new MaterialRevision(hgmaterial, oneModifiedFile("13", date.plusDays(2).toDate()), oneModifiedFile("12", date.plusDays(2).toDate()), oneModifiedFile("11", date.plusDays(3).toDate())), new MaterialRevision(svnMaterial, oneModifiedFile("23", date.plusDays(6).toDate()), oneModifiedFile("22", date.plusDays(2).toDate()), oneModifiedFile("21", date.plusDays(2).toDate())));
long second = save(pipelineConfig, 2, 0.0, new MaterialRevision(hgmaterial, oneModifiedFile("15", date.plusDays(3).toDate()), oneModifiedFile("14", date.plusDays(2).toDate())), new MaterialRevision(svnMaterial, oneModifiedFile("25", date.plusDays(5).toDate())));
PipelineTimeline pipelineTimeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
pipelineRepository.updatePipelineTimeline(pipelineTimeline, new ArrayList<>());
Collection<PipelineTimelineEntry> modifications = pipelineTimeline.getEntriesFor(PIPELINE_NAME);
assertThat(modifications.size(), is(2));
assertThat(modifications, hasItem(expected(first, new HashMap<String, List<PipelineTimelineEntry.Revision>>() {
{
put(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(2).toDate(), "123", hgmaterial.getFingerprint(), 8)));
put(svnMaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(6).toDate(), "456", svnMaterial.getFingerprint(), 12)));
}
}, 1)));
assertThat(modifications, hasItem(expected(second, new HashMap<String, List<PipelineTimelineEntry.Revision>>() {
{
put(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(3).toDate(), "234", hgmaterial.getFingerprint(), 9)));
put(svnMaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(5).toDate(), "345", svnMaterial.getFingerprint(), 10)));
}
}, 2)));
}
use of com.thoughtworks.go.server.domain.PipelineTimeline in project gocd by gocd.
the class PipelineRepositoryIntegrationTest method shouldAddExistingPipelinesToTimelineForNewTimeline.
@Test
public void shouldAddExistingPipelinesToTimelineForNewTimeline() {
HgMaterial hgmaterial = MaterialsMother.hgMaterial(UUID.randomUUID().toString());
PipelineConfig pipelineConfig = createPipelineConfig(PIPELINE_NAME, "stage", "job");
pipelineConfig.setMaterialConfigs(new MaterialConfigs(hgmaterial.config()));
DateTime date = new DateTime(1984, 12, 23, 0, 0, 0, 0);
long firstId = createPipeline(hgmaterial, pipelineConfig, 1, oneModifiedFile("3", date.plusDays(2).toDate()), oneModifiedFile("2", date.plusDays(2).toDate()), oneModifiedFile("1", date.plusDays(3).toDate()));
long secondId = createPipeline(hgmaterial, pipelineConfig, 2, oneModifiedFile("5", date.plusDays(1).toDate()), oneModifiedFile("4", date.toDate()));
PipelineTimeline mods = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
mods.update();
assertThat(pipelineSqlMapDao.pipelineByIdWithMods(firstId).getNaturalOrder(), is(1.0));
assertThat(pipelineSqlMapDao.pipelineByIdWithMods(secondId).getNaturalOrder(), is(0.5));
PipelineTimeline modsAfterReboot = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
modsAfterReboot.update();
}
use of com.thoughtworks.go.server.domain.PipelineTimeline in project gocd by gocd.
the class PipelineRepositoryIntegrationTest method shouldReturnEarliestPMRFor1Material.
@Test
public void shouldReturnEarliestPMRFor1Material() throws Exception {
HgMaterial hgmaterial = MaterialsMother.hgMaterial("first");
PipelineConfig pipelineConfig = createPipelineConfig(PIPELINE_NAME, "stage", "job");
pipelineConfig.setMaterialConfigs(new MaterialConfigs(hgmaterial.config()));
DateTime date = new DateTime(1984, 12, 23, 0, 0, 0, 0);
long firstId = createPipeline(hgmaterial, pipelineConfig, 1, oneModifiedFile("3", date.plusDays(2).toDate()), oneModifiedFile("2", date.plusDays(2).toDate()), oneModifiedFile("1", date.plusDays(3).toDate()));
long secondId = createPipeline(hgmaterial, pipelineConfig, 2, oneModifiedFile("5", date.plusDays(1).toDate()), oneModifiedFile("4", date.toDate()));
PipelineTimeline pipelineTimeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
ArrayList<PipelineTimelineEntry> entries = new ArrayList<>();
pipelineRepository.updatePipelineTimeline(pipelineTimeline, entries);
assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME).size(), is(2));
assertThat(entries.size(), is(2));
assertThat(entries, hasItem(expected(firstId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(2).toDate(), "123", hgmaterial.getFingerprint(), 10))), 1)));
assertThat(entries, hasItem(expected(secondId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(1).toDate(), "12", hgmaterial.getFingerprint(), 8))), 2)));
assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME), hasItem(expected(firstId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(2).toDate(), "123", hgmaterial.getFingerprint(), 10))), 1)));
assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME), hasItem(expected(secondId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(1).toDate(), "12", hgmaterial.getFingerprint(), 8))), 2)));
assertThat(pipelineTimeline.maximumId(), is(secondId));
long thirdId = createPipeline(hgmaterial, pipelineConfig, 3, oneModifiedFile("30", date.plusDays(10).toDate()));
pipelineRepository.updatePipelineTimeline(pipelineTimeline, new ArrayList<>());
assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME).size(), is(3));
assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME), hasItem(expected(thirdId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(10).toDate(), "1234", hgmaterial.getFingerprint(), 12))), 3)));
assertThat(pipelineTimeline.maximumId(), is(thirdId));
assertThat(pipelineSqlMapDao.pipelineByIdWithMods(firstId).getNaturalOrder(), is(1.0));
assertThat(pipelineSqlMapDao.pipelineByIdWithMods(secondId).getNaturalOrder(), is(0.5));
assertThat(pipelineSqlMapDao.pipelineByIdWithMods(thirdId).getNaturalOrder(), is(2.0));
PipelineTimeline pipelineTimeline2 = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
pipelineRepository.updatePipelineTimeline(pipelineTimeline2, new ArrayList<>());
}
use of com.thoughtworks.go.server.domain.PipelineTimeline in project gocd by gocd.
the class AutoBuildTriangleDependencyTest method setUp.
@Before
public void setUp() throws Exception {
goConfigService = mock(GoConfigService.class);
cruiseConfig = mock(BasicCruiseConfig.class);
pipelineService = mock(PipelineService.class);
materialChecker = mock(MaterialChecker.class);
materialRepository = mock(MaterialRepository.class);
pipelineTimeline = mock(PipelineTimeline.class);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(materialChecker.hasPipelineEverRunWith(any(String.class), any(MaterialRevisions.class))).thenReturn(false);
serverHealthService = new ServerHealthService();
}
use of com.thoughtworks.go.server.domain.PipelineTimeline in project gocd by gocd.
the class PipelineRepository method updatePipelineTimeline.
@SuppressWarnings({ "unchecked" })
public void updatePipelineTimeline(final PipelineTimeline pipelineTimeline, final List<PipelineTimelineEntry> tempEntriesForRollback) {
getHibernateTemplate().execute(new HibernateCallback() {
private static final int PIPELINE_NAME = 0;
private static final int ID = 1;
private static final int COUNTER = 2;
private static final int MODIFIED_TIME = 3;
private static final int FINGERPRINT = 4;
private static final int NATURAL_ORDER = 5;
private static final int REVISION = 6;
private static final int FOLDER = 7;
private static final int MOD_ID = 8;
private static final int PMR_ID = 9;
public Object doInHibernate(Session session) throws HibernateException, SQLException {
LOGGER.info("Start updating pipeline timeline");
List<Object[]> matches = retrieveTimeline(session, pipelineTimeline);
List<PipelineTimelineEntry> newPipelines = populateFrom(matches);
addEntriesToPipelineTimeline(newPipelines, pipelineTimeline, tempEntriesForRollback);
updateNaturalOrdering(session, newPipelines);
LOGGER.info("Pipeline timeline updated");
return null;
}
private void updateNaturalOrdering(Session session, List<PipelineTimelineEntry> pipelines) {
for (PipelineTimelineEntry pipeline : pipelines) {
if (pipeline.hasBeenUpdated()) {
updateNaturalOrderForPipeline(session, pipeline.getId(), pipeline.naturalOrder());
}
}
}
private List<Object[]> loadTimeline(SQLQuery query) {
long startedAt = System.currentTimeMillis();
List<Object[]> matches = (List<Object[]>) query.list();
long duration = System.currentTimeMillis() - startedAt;
if (duration > 1000) {
LOGGER.warn("updating in memory pipeline-timeline took: " + duration + " ms");
}
return matches;
}
private List<Object[]> retrieveTimeline(Session session, PipelineTimeline pipelineTimeline) {
SQLQuery query = session.createSQLQuery(queryExtensions.retrievePipelineTimeline());
query.setLong(0, pipelineTimeline.maximumId());
List<Object[]> matches = loadTimeline(query);
sortTimeLineByPidAndPmrId(matches);
return matches;
}
private void sortTimeLineByPidAndPmrId(List<Object[]> matches) {
Collections.sort(matches, new Comparator<Object[]>() {
@Override
public int compare(Object[] m1, Object[] m2) {
long id1 = id(m1);
long id2 = id(m2);
if (id1 == id2) {
return (int) (pmrId(m1) - pmrId(m2));
}
return (int) (id1 - id2);
}
});
}
private List<PipelineTimelineEntry> populateFrom(List<Object[]> matches) {
ArrayList<PipelineTimelineEntry> newPipelines = new ArrayList<>();
if (matches.isEmpty()) {
return newPipelines;
}
Map<String, List<PipelineTimelineEntry.Revision>> revisions = new HashMap<>();
String name = null;
long curId = -1;
Integer counter = null;
double naturalOrder = 0.0;
PipelineTimelineEntry entry = null;
for (int i = 0; i < matches.size(); i++) {
Object[] row = matches.get(i);
long id = id(row);
if (curId != id) {
name = pipelineName(row);
curId = id;
counter = counter(row);
revisions = new HashMap<>();
naturalOrder = naturalOrder(row);
}
String fingerprint = fingerprint(row);
if (!revisions.containsKey(fingerprint)) {
revisions.put(fingerprint, new ArrayList<>());
}
revisions.get(fingerprint).add(rev(row));
int nextI = i + 1;
if ((//new pipeline instance starts in next record, so capture this one
(nextI < matches.size() && id(matches.get(nextI)) != curId) || nextI == matches.size())) {
//this is the last record, so capture it
entry = new PipelineTimelineEntry(name, curId, counter, revisions, naturalOrder);
newPipelines.add(entry);
}
}
return newPipelines;
}
private String folder(Object[] row) {
return (String) row[FOLDER];
}
private PipelineTimelineEntry.Revision rev(Object[] row) {
return new PipelineTimelineEntry.Revision(modifiedTime(row), stringRevision(row), folder(row), modId(row));
}
private long pmrId(Object[] row) {
return ((BigInteger) row[PMR_ID]).longValue();
}
private long modId(Object[] row) {
return ((BigInteger) row[MOD_ID]).longValue();
}
private double naturalOrder(Object[] row) {
return (Double) row[NATURAL_ORDER];
}
private Date modifiedTime(Object[] row) {
return (Date) row[MODIFIED_TIME];
}
private String stringRevision(Object[] row) {
return (String) row[REVISION];
}
private String fingerprint(Object[] row) {
return String.valueOf(row[FINGERPRINT]);
}
private String pipelineName(Object[] row) {
return (String) row[PIPELINE_NAME];
}
private int counter(Object[] row) {
return row[COUNTER] == null ? -1 : ((BigInteger) row[COUNTER]).intValue();
}
private long id(Object[] first) {
return ((BigInteger) first[ID]).longValue();
}
});
}
Aggregations