Skip to content
Permalink
Browse files

Merge pull request #1201 from morrone/libjobspec

libjobspec: Initial flux jobspec parser
  • Loading branch information...
garlick committed Oct 9, 2017
2 parents c43a1f1 + 596a13f commit 9d3b4b18fb1c32af2ebda75a1fe4ad84350dd0da
Showing with 1,615 additions and 1 deletion.
  1. +2 −0 .travis.yml
  2. +28 −0 config/x_ac_yamlcpp.m4
  3. +3 −0 configure.ac
  4. +2 −1 src/Makefile.am
  5. +1 −0 src/cmd/.gitignore
  6. +14 −0 src/cmd/Makefile.am
  7. +80 −0 src/cmd/flux-jobspec-validate.cpp
  8. +12 −0 src/common/Makefile.am
  9. +1 −0 src/common/libjobspec/.gitignore
  10. +16 −0 src/common/libjobspec/Makefile.am
  11. +11 −0 src/common/libjobspec/flux-jobspec.pc.in
  12. +540 −0 src/common/libjobspec/jobspec.cpp
  13. +121 −0 src/common/libjobspec/jobspec.hpp
  14. +4 −0 src/include/flux/jobspec.hpp
  15. +17 −0 t/jobspec/invalid/attributes_bad_entry.yaml
  16. +14 −0 t/jobspec/invalid/attributes_not_mapping.yaml
  17. +1 −0 t/jobspec/invalid/invalid_yaml1.yaml
  18. +13 −0 t/jobspec/invalid/missing_attributes.yaml
  19. +7 −0 t/jobspec/invalid/missing_resources.yaml
  20. +9 −0 t/jobspec/invalid/missing_tasks.yaml
  21. +13 −0 t/jobspec/invalid/missing_version.yaml
  22. +16 −0 t/jobspec/invalid/resource_count_bad_type.yaml
  23. +17 −0 t/jobspec/invalid/resource_count_missing_max.yaml
  24. +17 −0 t/jobspec/invalid/resource_count_missing_min.yaml
  25. +17 −0 t/jobspec/invalid/resource_count_missing_operand.yaml
  26. +17 −0 t/jobspec/invalid/resource_count_missing_operator.yaml
  27. +14 −0 t/jobspec/invalid/resource_count_scalar_bad_value.yaml
  28. +15 −0 t/jobspec/invalid/resource_exclusive_invalid.yaml
  29. +17 −0 t/jobspec/invalid/resource_exclusive_not_scalar.yaml
  30. +17 −0 t/jobspec/invalid/resource_id_not_scalar.yaml
  31. +16 −0 t/jobspec/invalid/resource_label_not_scalar.yaml
  32. +13 −0 t/jobspec/invalid/resource_missing_count.yaml
  33. +13 −0 t/jobspec/invalid/resource_missing_type.yaml
  34. +14 −0 t/jobspec/invalid/resource_not_mapping.yaml
  35. +13 −0 t/jobspec/invalid/resource_slot_not_labelled.yaml
  36. +17 −0 t/jobspec/invalid/resource_unit_not_scalar.yaml
  37. +14 −0 t/jobspec/invalid/resources_not_sequence.yaml
  38. +13 −0 t/jobspec/invalid/task_count_not_mapping.yaml
  39. +13 −0 t/jobspec/invalid/task_missing_command.yaml
  40. +12 −0 t/jobspec/invalid/task_missing_count.yaml
  41. +13 −0 t/jobspec/invalid/task_missing_slot.yaml
  42. +11 −0 t/jobspec/invalid/task_not_mapping.yaml
  43. +14 −0 t/jobspec/invalid/tasks_not_sequence.yaml
  44. +14 −0 t/jobspec/invalid/version_bad_number.yaml
  45. +15 −0 t/jobspec/invalid/version_not_scalar.yaml
  46. +14 −0 t/jobspec/valid/basic.yaml
  47. +19 −0 t/jobspec/valid/example1.yaml
  48. +16 −0 t/jobspec/valid/example2.yaml
  49. +16 −0 t/jobspec/valid/use_case_1.1.yaml
  50. +20 −0 t/jobspec/valid/use_case_1.2.yaml
  51. +22 −0 t/jobspec/valid/use_case_1.3.yaml
  52. +22 −0 t/jobspec/valid/use_case_1.4.yaml
  53. +41 −0 t/jobspec/valid/use_case_1.5.yaml
  54. +22 −0 t/jobspec/valid/use_case_1.6.yaml
  55. +19 −0 t/jobspec/valid/use_case_1.7.yaml
  56. +16 −0 t/jobspec/valid/use_case_2.1.yaml
  57. +16 −0 t/jobspec/valid/use_case_2.2.yaml
  58. +16 −0 t/jobspec/valid/use_case_2.3.yaml
  59. +35 −0 t/jobspec/valid/use_case_2.4.yaml
  60. +19 −0 t/jobspec/valid/use_case_2.5.yaml
  61. +20 −0 t/jobspec/valid/use_case_2.6.yaml
  62. +21 −0 t/t0018-jobspec.t
@@ -49,6 +49,8 @@ addons:
- apport # for coredumps
- gdb
- valgrind
- libyaml-cpp-dev
- libboost-dev # for yaml-cpp 0.5.1. >=0.5.2 no longer need boost

coverity_scan:
project:
@@ -0,0 +1,28 @@
AC_DEFUN([X_AC_YAMLCPP], [

PKG_CHECK_MODULES([YAMLCPP], [yaml-cpp >= 0.5.1],
[enable_jobspec=yes], [enable_jobspec=no])

if test "$enable_jobspec" = yes; then
ac_save_LIBS="$LIBS"
LIBS="$LIBS $YAMLCPP_LIBS"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $YAMLCPP_CFLAGS"
AC_LANG_PUSH([C++])

# YAML::Node::Mark() is only present in yaml-cpp beginning
# with release 0.5.3.
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <yaml-cpp/yaml.h>],
[YAML::Node node; node.Mark()])],
[AC_DEFINE([HAVE_YAML_MARK], [1],
[Define to 1 if yaml-cpp library has YAML::Node::Mark()])],
[])

AC_LANG_POP([C++])
LIBS="$ac_save_LIBS"
CFLAGS="$ac_save_CFLAGS"
fi

AM_CONDITIONAL([ENABLE_JOBSPEC], [test "$enable_jobspec" = yes])
]
)
@@ -175,6 +175,7 @@ AX_LUA_LIBS
X_AC_ZEROMQ
X_AC_MUNGE
X_AC_JANSSON
X_AC_YAMLCPP
PKG_CHECK_MODULES([HWLOC], [hwloc >= 1.4], [], [])
PKG_CHECK_MODULES([SQLITE], [sqlite3], [], [])
LX_FIND_MPI
@@ -271,6 +272,8 @@ AC_CONFIG_FILES( \
src/common/libsubprocess/Makefile \
src/common/libcompat/Makefile \
src/common/liboptparse/Makefile \
src/common/libjobspec/Makefile \
src/common/libjobspec/flux-jobspec.pc \
src/bindings/Makefile \
src/bindings/lua/Makefile \
src/bindings/python/Makefile \
@@ -8,4 +8,5 @@ check-local: all

noinst_HEADERS = \
include/flux/core.h \
include/flux/optparse.h
include/flux/optparse.h \
include/flux/jobspec.hpp
@@ -2,6 +2,7 @@
/flux-comms
/flux-comms-stats
/flux-event
/flux-jobspec-validate
/flux-jstat
/flux-keygen
/flux-kvs
@@ -9,6 +9,10 @@ AM_CPPFLAGS = \
-I$(top_srcdir) -I$(top_srcdir)/src/include \
$(ZMQ_CFLAGS)

AM_CXXFLAGS = \
$(WARNING_CXXFLAGS) \
$(CODE_COVERAGE_CXXFLAGS)

fluxcmd_ldadd = \
$(top_builddir)/src/common/libkvs/libkvs.la \
$(top_builddir)/src/common/libflux-internal.la \
@@ -69,6 +73,16 @@ fluxcmd_PROGRAMS = \
flux-start \
flux-jstat

if ENABLE_JOBSPEC
fluxcmd_PROGRAMS += \
flux-jobspec-validate

flux_jobspec_validate_SOURCES = flux-jobspec-validate.cpp
flux_jobspec_validate_LDADD = \
$(top_builddir)/src/common/libjobspec/libjobspec.la \
$(YAMLCPP_LIBS)
endif

flux_start_LDADD = \
$(fluxcmd_ldadd) \
$(LIBUTIL)
@@ -0,0 +1,80 @@
/*****************************************************************************\
* Copyright (c) 2017 Lawrence Livermore National Security, LLC. Produced at
* the Lawrence Livermore National Laboratory (cf, AUTHORS, DISCLAIMER.LLNS).
* LLNL-CODE-658032 All rights reserved.
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the license, or (at your option)
* any later version.
*
* Flux is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* See also: http://www.gnu.org/licenses/
\*****************************************************************************/

#include <iostream>
#include <fstream>
#include <string>

#include <flux/jobspec.hpp>
#include <yaml-cpp/yaml.h>

using namespace std;
using namespace Flux::Jobspec;

void parse_yaml_stream_docs (std::istream& js_stream)
{
bool first = true;
for (auto&& rootnode: YAML::LoadAll (js_stream)) {
Jobspec js;
if (!first)
cout << endl;
else
first = false;
js = Jobspec (rootnode);
cout << js;
}
}

int main(int argc, char *argv[])
{
try {
if (argc == 1) {
parse_yaml_stream_docs (cin);
} else {
for (int i = 1; i < argc; i++) {
std::ifstream js_file (argv[i]);
if (js_file.fail()) {
cerr << argv[0] << ": Unable to open file \"" << argv[i] << "\"" << endl;
return 1;
}
parse_yaml_stream_docs (js_file);
}
}
} catch (parse_error& e) {
cerr << argv[0] << ": ";
if (e.position != -1)
cerr << argv[0] << "position " << e.position << ", ";
if (e.line != -1)
cerr << argv[0] << "line " << e.line << ", ";
if (e.column != -1)
cerr << "column " << e.column << ", ";
cerr << e.what() << endl;
return 2;
} catch (...) {
cerr << argv[0] << ": Unknown non-standard exception" << endl;
return 3;
}

return 0;
}
@@ -13,6 +13,10 @@ SUBDIRS = libtap \
libcompat \
liboptparse

if ENABLE_JOBSPEC
SUBDIRS += libjobspec
endif

AM_CFLAGS = $(WARNING_CFLAGS) $(CODE_COVERAGE_CFLAGS)
AM_LDFLAGS = $(CODE_COVERAGE_LIBS)

@@ -36,6 +40,9 @@ libflux_internal_la_LIBADD = \
libflux_internal_la_LDFLAGS = $(san_ld_zdef_flag)

lib_LTLIBRARIES = libflux-core.la libflux-optparse.la
if ENABLE_JOBSPEC
lib_LTLIBRARIES += libflux-jobspec.la
endif
fluxlib_LTLIBRARIES = libpmi.la libpmi2.la

libflux_core_la_SOURCES =
@@ -59,6 +66,11 @@ libflux_optparse_la_LDFLAGS = \
-shared -export-dynamic --disable-static \
$(san_ld_zdef_flag)

if ENABLE_JOBSPEC
libflux_jobspec_la_SOURCES =
libflux_jobspec_la_LIBADD = $(builddir)/libjobspec/libjobspec.la
endif

libpmi_la_SOURCES =
libpmi_la_LIBADD = \
$(builddir)/libpmi/libpmi.la \
@@ -0,0 +1 @@
/flux-jobspec.pc
@@ -0,0 +1,16 @@
if ENABLE_JOBSPEC
noinst_LTLIBRARIES = libjobspec.la

libjobspec_la_CXXFLAGS = \
$(WARNING_CXXFLAGS) \
$(CODE_COVERAGE_CXXFLAGS) \
$(YAMLCPP_CFLAGS)
libjobspec_la_LIBADD = $(CODE_COVERAGE_LIBS) $(YAMLCPP_LIBS)
libjobspec_la_SOURCES = jobspec.cpp jobspec.hpp

fluxinclude_HEADERS = jobspec.hpp

if WITH_PKG_CONFIG
pkgconfig_DATA = flux-jobspec.pc
endif
endif
@@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: flux-jobspec
Description: Flux Resource Manager Jobspec Parser
Version: @PACKAGE_VERSION@
Requires: Yaml-cpp
Libs: -L${libdir} -lflux-jobspec
Cflags: -I${includedir}
Oops, something went wrong.

0 comments on commit 9d3b4b1

Please sign in to comment.
You can’t perform that action at this time.