Commit c113ebce authored by Leigh Stoller's avatar Leigh Stoller

A little reorg so I can share some code (the response converters).

parent fe3aa4c7
#!/usr/bin/perl -wT
#
# Copyright (c) 2008-2015 University of Utah and the Flux Group.
# Copyright (c) 2008-2016 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
......@@ -79,6 +79,7 @@ sub SetGeniVersion($)
$API_VERSION = 4;
}
}
sub InitModule($) { SetGeniVersion($_[0]); }
#
# Tell the client what API revision we support. The correspondence
......@@ -688,6 +689,82 @@ sub ListImages()
return $response;
}
#----------------------------------------------------------------------
# Morph the ProtoGENI response (a hash with three keys; a
# GeniResponse) into a GENI AMv1 response (a single value or a fault if
# there is an error).
#
# $geni_response is an XML RPC response, which is a three element hash. The
# value element is the GeniResponse hash.
#----------------------------------------------------------------------
sub ConvertResponseV1($)
{
my ($geni_response) = @_;
my $decoder = Frontier::RPC2->new();
my $response;
if (GeniResponse::IsError($geni_response)) {
# An error result gets mapped to an XML RPC fault
$response =
$decoder->encode_fault(GeniResponse::code($geni_response),
GeniResponse::output($geni_response));
} else {
# A successful result means return the value
$response =
$decoder->encode_response(GeniResponse::value($geni_response));
}
return $response;
}
#----------------------------------------------------------------------
# Morph the ProtoGENI response (a hash with three keys; a
# GeniResponse) into a GENI AMv2 response (same value and output, but
# more complex code format).
#
# $geni_response is an XML RPC response, which is a three element hash. The
# value element is the GeniResponse hash.
#----------------------------------------------------------------------
sub ConvertResponseV2($)
{
my ($geni_response) = @_;
my $decoder = Frontier::RPC2->new();
my $version = $geni_response->{"geni_api"};
my $am_code = GeniResponse::code($geni_response);
# For standard GENI errors, the geni_code is the same as our am_code
my $geni_code = $am_code;
if ($am_code < GeniResponse::GENIRESPONSE_SUCCESS() ||
$am_code > GeniResponse::GENIRESPONSE_ALREADYEXISTS()) {
# If the code is outside of the standard GENI code range, set
# the geni_code to ERROR
$geni_code = GeniResponse::GENIRESPONSE_ERROR();
}
my $blob = {
"value" => GeniResponse::value($geni_response),
"output" => GeniResponse::output($geni_response),
"code" => {
"geni_code" => $geni_code,
"am_code" => $am_code,
"am_type" => "protogeni"
}
};
if (exists($geni_response->{'protogeni_error_log'})) {
$blob->{'code'}->{'protogeni_error_log'} =
$geni_response->{'protogeni_error_log'};
}
if (exists($geni_response->{'protogeni_error_url'})) {
$blob->{'code'}->{'protogeni_error_url'} =
$geni_response->{'protogeni_error_url'};
}
if (defined($version)) {
$blob->{"geni_api"} = $version;
}
return $decoder->encode_response($blob);
}
###############################################################################
# AM API V3
###############################################################################
......
#!/usr/bin/perl -w
#
# Copyright (c) 2008-2013 University of Utah and the Flux Group.
# Copyright (c) 2008-2016 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
......@@ -85,86 +85,10 @@ if ($GENI_VERSION eq "1.0" || $GENI_VERSION eq "2.0") {
};
}
#----------------------------------------------------------------------
# Morph the ProtoGENI response (a hash with three keys; a
# GeniResponse) into a GENI AMv1 response (a single value or a fault if
# there is an error).
#
# $geni_response is an XML RPC response, which is a three element hash. The
# value element is the GeniResponse hash.
#----------------------------------------------------------------------
sub ConvertResponseV1($)
{
my ($geni_response) = @_;
my $decoder = Frontier::RPC2->new();
my $response;
if (GeniResponse::IsError($geni_response)) {
# An error result gets mapped to an XML RPC fault
$response =
$decoder->encode_fault(GeniResponse::code($geni_response),
GeniResponse::output($geni_response));
} else {
# A successful result means return the value
$response =
$decoder->encode_response(GeniResponse::value($geni_response));
}
return $response;
}
#----------------------------------------------------------------------
# Morph the ProtoGENI response (a hash with three keys; a
# GeniResponse) into a GENI AMv2 response (same value and output, but
# more complex code format).
#
# $geni_response is an XML RPC response, which is a three element hash. The
# value element is the GeniResponse hash.
#----------------------------------------------------------------------
sub ConvertResponseV2($)
{
my ($geni_response) = @_;
my $decoder = Frontier::RPC2->new();
my $version = $geni_response->{"geni_api"};
my $am_code = GeniResponse::code($geni_response);
# For standard GENI errors, the geni_code is the same as our am_code
my $geni_code = $am_code;
if ($am_code < GeniResponse::GENIRESPONSE_SUCCESS() ||
$am_code > GeniResponse::GENIRESPONSE_ALREADYEXISTS()) {
# If the code is outside of the standard GENI code range, set
# the geni_code to ERROR
$geni_code = GeniResponse::GENIRESPONSE_ERROR();
}
my $blob = {
"value" => GeniResponse::value($geni_response),
"output" => GeniResponse::output($geni_response),
"code" => {
"geni_code" => $geni_code,
"am_code" => $am_code,
"am_type" => "protogeni"
}
};
if (exists($geni_response->{'protogeni_error_log'})) {
$blob->{'code'}->{'protogeni_error_log'} =
$geni_response->{'protogeni_error_log'};
}
if (exists($geni_response->{'protogeni_error_url'})) {
$blob->{'code'}->{'protogeni_error_url'} =
$geni_response->{'protogeni_error_url'};
}
if (defined($version)) {
$blob->{"geni_api"} = $version;
}
return $decoder->encode_response($blob);
}
if ($GENI_VERSION eq "1.0") {
$GENI_RESPONSE_CONVERTER = \&ConvertResponseV1;
$GENI_RESPONSE_CONVERTER = \&GeniAM::ConvertResponseV1;
} else {
$GENI_RESPONSE_CONVERTER = \&ConvertResponseV2;
$GENI_RESPONSE_CONVERTER = \&GeniAM::ConvertResponseV2;
}
1;
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