use of com.google.api.ads.admanager.axis.v202202.Statement in project open-kilda by telstra.
the class NeoDriver method getPath.
/**
* {@inheritDoc}
*/
@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) throws UnroutablePathException {
long latency = 0L;
List<PathNode> forwardNodes = new LinkedList<>();
List<PathNode> reverseNodes = new LinkedList<>();
if (!flow.isOneSwitchFlow()) {
Statement statement = getPathQuery(flow, strategy);
logger.debug("QUERY: {}", statement.toString());
try (Session session = driver.session()) {
StatementResult result = session.run(statement);
try {
Record record = result.next();
LinkedList<Relationship> isls = new LinkedList<>();
record.get(0).asPath().relationships().forEach(isls::add);
int seqId = 0;
for (Relationship isl : isls) {
latency += isl.get("latency").asLong();
forwardNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
forwardNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, 0L));
seqId++;
}
seqId = 0;
Collections.reverse(isls);
for (Relationship isl : isls) {
reverseNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
reverseNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, 0L));
seqId++;
}
} catch (NoSuchRecordException e) {
throw new UnroutablePathException(flow);
}
}
} else {
logger.info("No path computation for one-switch flow");
}
return new ImmutablePair<>(new PathInfoData(latency, forwardNodes), new PathInfoData(latency, reverseNodes));
}
use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.
the class StatementBuilderTest method testLimitOffsetDefaults.
@Test
public void testLimitOffsetDefaults() {
StatementBuilder statementBuilder = new StatementBuilder();
Statement initialOffset = statementBuilder.limit(100).toStatement();
assertEquals("LIMIT 100", initialOffset.getQuery());
Statement increasedOffset = statementBuilder.increaseOffsetBy(100).toStatement();
assertEquals("LIMIT 100 OFFSET 100", increasedOffset.getQuery());
}
use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.
the class StatementBuilderTest method testFrom_stripsFrom.
@Test
public void testFrom_stripsFrom() {
StatementBuilder statementBuilder = new StatementBuilder();
Statement statement = statementBuilder.from("FROM line_item").toStatement();
assertEquals("FROM line_item", statement.getQuery());
}
use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.
the class GetActiveActivities method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
ActivityServiceInterface activityService = adManagerServices.get(session, ActivityServiceInterface.class);
// Create a statement to select activities.
StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", ActivityStatus.ACTIVE.toString());
// Retrieve a small amount of activities at a time, paging through
// until all activities have been retrieved.
int totalResultSetSize = 0;
do {
ActivityPage page = activityService.getActivitiesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each activity.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Activity activity : page.getResults()) {
System.out.printf("%d) Activity with ID %d, name '%s', and type '%s' was found.%n", i++, activity.getId(), activity.getName(), activity.getType());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.
the class GetActiveActivityGroups method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
ActivityGroupServiceInterface activityGroupService = adManagerServices.get(session, ActivityGroupServiceInterface.class);
// Create a statement to select activity groups.
StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", ActivityGroupStatus.ACTIVE.toString());
// Retrieve a small amount of activity groups at a time, paging through
// until all activity groups have been retrieved.
int totalResultSetSize = 0;
do {
ActivityGroupPage page = activityGroupService.getActivityGroupsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each activity group.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (ActivityGroup activityGroup : page.getResults()) {
System.out.printf("%d) Activity group with ID %d and name '%s' was found.%n", i++, activityGroup.getId(), activityGroup.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Aggregations