Skip to content
Permalink
Browse files
Code cleanup for statistics and parameters
  • Loading branch information
dspavlov committed Mar 15, 2019
1 parent 0d652d0 commit 69f562f65bae687ac8288cbdedb3cfa88e657e6a
Showing 5 changed files with 49 additions and 57 deletions.
@@ -142,10 +142,10 @@ protected Stream<BuildTypeCompacted> buildTypesCompactedStream(int srvIdMaskHigh
*/
public List<BuildTypeCompacted> compositeBuildTypesCompacted(int srvIdMaskHigh, @Nullable String projectId) {
final int nameId = compactor.getStringId("buildConfigurationType");
final int valueId = compactor.getStringId("COMPOSITE");
final int valId = compactor.getStringId("COMPOSITE");

return buildTypesCompactedStream(srvIdMaskHigh, projectId)
.filter(bt -> bt.settings().findPropertyStringId(nameId) == valueId)
.filter(bt -> bt.settings().findPropertyStringId(nameId) == valId)
.collect(Collectors.toList());
}

@@ -46,61 +46,56 @@ public ParametersCompacted(IStringCompactor compactor, List<Property> ref) {
keys = new GridIntList(size);
values = new GridIntList(size);
for (Property next : ref) {
final String name = next.name();
String name = next.name();
if (Strings.isNullOrEmpty(name))
continue;

final String value = next.getValue();
if (Strings.isNullOrEmpty(value))
String strVal = next.getValue();
if (Strings.isNullOrEmpty(strVal))
continue;
final int val = compactor.getStringId(value);
final int stringId = compactor.getStringId(name);

keys.add(stringId);
int val = compactor.getStringId(strVal);
int strId = compactor.getStringId(name);

keys.add(strId);
values.add(val);
}
}

public Parameters toParameters(IStringCompactor compactor) {
List<Property> properties = null;
List<Property> props = null;

if (keys.size() > 0) {
properties = new ArrayList<>();
if (!keys.isEmpty()) {
props = new ArrayList<>();

final int size = keys.size();

for (int i = 0; i < size && i < values.size(); i++) {
final int nameid = keys.get(i);
String name = compactor.getStringFromId(nameid);
String value = compactor.getStringFromId(values.get(i));
String val = compactor.getStringFromId(values.get(i));

properties.add(new Property(name, value));
props.add(new Property(name, val));
}
}

return new Parameters(properties);
return new Parameters(props);
}

public int findPropertyStringId(int propertyCode) {
int value = -1;

if (keys != null) {
final int size = keys.size();

for (int i = 0; i < size; i++) {
final int nameid = keys.get(i);
public int findPropertyStringId(int propCode) {
if (keys == null)
return -1;

if (nameid != propertyCode)
continue;
final int size = keys.size();

if (i >= values.size())
break;
for (int i = 0; i < size; i++) {
int nameid = keys.get(i);

value = values.get(i);
}
if (nameid == propCode)
return i < values.size() ? values.get(i) : -1;
}

return value;
return -1;
}

/** {@inheritDoc} */
@@ -596,7 +596,7 @@ public Invocation toInvocation(IStringCompactor compactor) {
}

return new Invocation(getId())
.withStatus((byte)failCode)
.withStatus(failCode)
.withStartDate(getStartDateTs())
.withChanges(changes());
}
@@ -615,8 +615,7 @@ public FatBuildCompacted setCancelled(IStringCompactor compactor) {
/**
* @return revisions list or null if revisions was not reported by TC/for older build versions in DB.
*/
@Nullable
public List<RevisionCompacted> revisions() {
@Nullable public List<RevisionCompacted> revisions() {
if (revisions == null)
return null;

@@ -18,6 +18,7 @@
package org.apache.ignite.ci.teamcity.ignited.fatbuild;

import com.google.common.base.Strings;
import java.util.List;
import org.apache.ignite.ci.tcmodel.conf.bt.Property;
import org.apache.ignite.ci.tcmodel.result.stat.Statistics;
import org.apache.ignite.ci.teamcity.ignited.IStringCompactor;
@@ -26,8 +27,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class StatisticsCompacted {
/** Logger. */
private static final Logger logger = LoggerFactory.getLogger(StatisticsCompacted.class);
@@ -39,32 +38,32 @@ public StatisticsCompacted() {
}

public StatisticsCompacted(IStringCompactor compactor, Statistics statistics) {
final List<Property> properties = statistics.properties();
final int size = properties.size();
final List<Property> props = statistics.properties();
final int size = props.size();
keys = new GridIntList(size);
values = new GridLongList(size);
int idx = 0;
for (Property next : properties) {

for (Property next : props) {
final String name = next.name();
if (Strings.isNullOrEmpty(name))
continue;

final String value = next.getValue();
if (Strings.isNullOrEmpty(value))
final String valStr = next.getValue();
if (Strings.isNullOrEmpty(valStr))
continue;

final long val;
try {
val = Long.parseLong(value);
val = Long.parseLong(valStr);
} catch (Exception e) {
logger.error("Statistics value is not numeric " + name + " skipped " + e.getMessage(), e);
continue;
}

final int stringId = compactor.getStringId(name);
final int strId = compactor.getStringId(name);

keys.add(stringId);
keys.add(strId);
values.add(val);
idx++;
}
}

@@ -73,29 +72,26 @@ public Long buildDuration(IStringCompactor compactor) {
if (buildDurationId == null)
return null;

long value = findPropertyValue(buildDurationId);
long val = findPropertyValue(buildDurationId);

if (value < 0) return null;
if (val < 0) return null;

return value;
return val;
}

private long findPropertyValue(int propertyCode) {
private long findPropertyValue(int propCode) {
if (keys == null)
return -1L;

final int size = keys.size();

long value = -1;
for (int i = 0; i < size; i++) {
final int nameid = keys.get(i);

if (nameid != propertyCode)
continue;

if (i >= values.size())
break;

value = values.get(i);
if (nameid == propCode)
return i < values.size() ? values.get(i) : -1;
}

return value;
return -1L;
}
}
@@ -36,11 +36,13 @@ public class Invocation {

/** Build id. */
private int buildId;

/** Status: An integer (actually byte) code from RunStat.RunStatus */
private byte status;

/** Change present: 0 - no changes, 1 - changes present, 2- unknown */
private byte changePresent;

/** Build Start date as timestamp. */
private long startDate;

0 comments on commit 69f562f

Please sign in to comment.