00001 #include "drms.h"
00002 #include "jsoc_main.h"
00003
00004 #define kSeries "series"
00005 #define kTablename "tname"
00006 #define kUndefined "undefined"
00007
00008 typedef enum
00009 {
00010 kCSErr_Success = 0,
00011 kCSErr_BadArg,
00012 kCSErr_OutOfMemory,
00013 kCSErr_BadQuery,
00014 kCSErr_CantCreateShadow
00015 } CSError_t;
00016
00017 char *module_name = "createshadow";
00018
00019
00020 ModuleArgs_t module_args[] =
00021 {
00022 {ARG_STRING, kSeries, "", "The series for which a shadow table is to be created."},
00023 {ARG_STRING, kTablename, kUndefined, "Optional - the name of the shadow-table to create. This is to be used for debugging since there is only one name that DRMS will recognize (<series name>_shadow). "},
00024 {ARG_END}
00025 };
00026
00027
00028 int DoIt(void)
00029 {
00030 CSError_t err = kCSErr_Success;
00031 int drmsstat = DRMS_SUCCESS;
00032
00033 const char *series = cmdparams_get_str(&cmdparams, kSeries, &drmsstat);
00034 const char *tname = cmdparams_get_str(&cmdparams, kTablename, &drmsstat);
00035
00036 if (drmsstat != DRMS_SUCCESS)
00037 {
00038 err = kCSErr_BadArg;
00039 }
00040 else
00041 {
00042 if (strcmp(tname, kUndefined) == 0)
00043 {
00044 tname = NULL;
00045 }
00046
00047 drms_series_setcreateshadows(drms_env, NULL);
00048 drmsstat = drms_series_createshadow(drms_env, series, tname);
00049
00050 if (drmsstat != DRMS_SUCCESS)
00051 {
00052 if (drmsstat == DRMS_ERROR_OUTOFMEMORY)
00053 {
00054 err = kCSErr_OutOfMemory;
00055 }
00056 else if (drmsstat == DRMS_ERROR_BADDBQUERY)
00057 {
00058 err = kCSErr_BadQuery;
00059 }
00060 else
00061 {
00062 err = kCSErr_CantCreateShadow;
00063 }
00064 }
00065 }
00066
00067 return err;
00068 }