All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 78969baa authored by Jonathon Duerig's avatar Jonathon Duerig

Complete rewrite of ptopgen from the ground up to use db/* classes. Checkpoint.

Basic framework is in place. Availability and printability is codified into
functions now. Node.pm modified so that lookups can be done in bulk for
efficiency. When making XML, we now create XML trees rather than printing
out XML fragments.
parent 98eb7972
......@@ -168,10 +168,19 @@ sub Lookup($$)
return undef
if (!$query_result || !$query_result->numrows);
return LookupRow($class, $query_result->fetchrow_hashref());
}
#
# Lookup a (physical) node based on an existing row from the database.
# Useful for bulk lookups.
#
sub LookupRow($$)
{
my ($class, $hash_orig) = @_;
#
# Make a copy of the array. Still fighting memory corruption error.
#
my $hash_orig = $query_result->fetchrow_hashref();
my $hash_copy = {};
foreach my $key (keys(%{ $hash_orig })) {
my $val = $hash_orig->{$key};
......@@ -190,7 +199,7 @@ sub Lookup($$)
# XXX debug
my $row = $self->{"DBROW"};
$nodeid = checknodeid($row->{'node_id'}, "From DB");
my $nodeid = checknodeid($row->{'node_id'}, "From DB");
# Add to cache.
$nodes{$nodeid} = $self;
......@@ -739,6 +748,16 @@ sub IsReserved($)
return 1;
}
#
# Set reserved member based on a database row. Useful for bulk lookups.
#
sub SetReservedRow($$)
{
my ($self, $reserved) = @_;
if ($reserved->{"node_id"} eq $self->node_id()) {
$self->{"RSRV"} = $reserved;
}
}
sub GetSubboss($$)
{
......
......@@ -29,12 +29,17 @@ use GeniHRN;
use GeniUtil;
use Carp qw(cluck carp);
use vars qw($RSPEC_0_1 $RSPEC_0_2 $RSPEC_2 $EMULAB_NS $XSI_NS $STITCH_NS
use vars qw($RSPEC_0_1 $RSPEC_0_2 $RSPEC_2
$RSPEC_0_1_NS $RSPEC_0_2_NS $RSPEC_2_NS
$EMULAB_NS $XSI_NS $STITCH_NS
$REQUEST_URL $MANIFEST_URL);
$RSPEC_0_1 = "0.1";
$RSPEC_0_2 = "0.2";
$RSPEC_2 = "2";
$RSPEC_0_1_NS = "http://www.protogeni.net/resources/rspec/0.1";
$RSPEC_0_2_NS = "http://www.protogeni.net/resources/rspec/0.2";
$RSPEC_2_NS = "http://www.protogeni.net/resources/rspec/2";
$EMULAB_NS = "http://www.protogeni.net/resources/rspec/ext/emulab/1";
$XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
$STITCH_NS = "http://hpn.east.isi.edu/rspec/ext/stitch/0.1/";
......@@ -753,7 +758,7 @@ sub CreateDocument($$)
{
my ($ns, $name) = @_;
my $doc = XML::LibXML::Document->createDocument("1.0", "UTF-8");
my $root = $doc->createElementNS($ns, "rs:$name");
my $root = $doc->createElementNS($ns, "$name");
$doc->setDocumentElement($root);
return $doc;
}
......
This diff is collapsed.
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
# TODO: USER_COMPONENT --> No caching, willPrint, available, etc.
use strict;
use English;
use Getopt::Std;
use Math::BigInt;
use List::Util 'shuffle';
#use lib "@prefix@/lib";
use lib "/usr/testbed/lib";
use lib ".";
use libdb;
use libadminctrl;
use libptopnew;
use Experiment;
use Lan;
use Node;
use NodeType;
use GeniXML;
sub processArgs();
sub consultDatabase();
sub process();
sub printResults();
libptopnew::Init();
#
# Turn off line buffering on output
#
$| = 1;
my $print_xml = 0;
my $print_format = "CRAPPY";
my $print_ns = $GeniXML::RSPEC_2_NS;
processArgs();
consultDatabase();
printResults();
sub processArgs()
{
}
sub consultDatabase()
{
my $dbresult;
my $row;
# Bulk lookup on nodes table
$dbresult = DBQueryFatal("select * from nodes");
while ($row = $dbresult->fetchrow_hashref()) {
libptopnew::CreateNode($row);
}
# Bulk lookup on reserved table
$dbresult = DBQueryFatal("select * from reserved");
while ($row = $dbresult->fetchrow_hashref()) {
libptopnew::Nodes()->{$row->{"node_id"}}->node()->SetReservedRow($row);
}
# Process each node adding ptypes and features
foreach my $current (values(%{ libptopnew::Nodes() })) {
if ($current->willPrint()) {
$current->processSwitch();
$current->processLocal();
$current->processWidearea();
}
}
}
sub printResults()
{
my $doc = GeniXML::CreateDocument($print_ns, "rspec");
my $rspec = $doc->documentElement();
foreach my $current (values(%{ libptopnew::Nodes() })) {
if ($current->willPrint()) {
if ($print_xml) {
$current->toXML($rspec);
} else {
print $current->toString()."\n";
}
}
}
if ($print_xml) {
print GeniXML::Serialize($rspec, 1)."\n";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment