230 likes | 379 Views
SRB API Tuitorial. Michael Wan San Diego Supercomputer Center mwan@sdsc.edu SRB URL:http://www.npaci.edu/Research/DI/srb/. SRB client API. Over 80 client API with release 1.1.8 Documented in Appendix A of user manual Function prototype in include/clStubExtern.h. SRB Client API.
E N D
SRB API Tuitorial Michael Wan San Diego Supercomputer Center mwan@sdsc.edu SRB URL:http://www.npaci.edu/Research/DI/srb/
SRB client API Over 80 client API with release 1.1.8 Documented in Appendix A of user manual Function prototype in include/clStubExtern.h
SRB Client API Data operations - srbObjCreate, srbObjOpen, srbObjRead, srbObjWrite, srbObjSeek, srbObjProxyOpr, srbObjReplicate, srbCreatCollect, srbIssueTicket, srbObjOpenWithTicket, API that interact MCAT Metadata query - srbGetDatasetInfo, srbGetdataDirInfo, srbListCollect, .... Metadata manipulation - srbModifyDataset, srbRegisterDataset, …. Admin API - srbRegisterUser, srbModifyUser, srbRegisterUserGrp, srbChkMdasAuth, ….
SRB API – getting started Makefile CL_CFLAGS+=-D$(PORTNAME) CL_CFLAGS+= -I$(srbDir)/src/include CL_CFLAGS+= -I$(srbDir)/src/catalog/include CL_LDADD+=-L$(libDir) -lSrbClient Include file #include "srbClient.h"
Sconnect.c – connect to a srb serversrbConn* srbConnect(char *srbHost, char* srbPort, char* srbAuth, char userName, char *domainName, char *authScheme, char *serverDn) conn = srbConnect (HOST, PORT, SRB_AUTH, USER, DOMAIN, AUTH_SCHEME, SERVER_DN);.clFinish(conn);
Sput.c – import a local file into SRBint srbObjCreate(srbConn* conn, int catType, char *objID, char *dataTypeName, char *resourceName, char collectionName, char *pathName, srb_long_t dataSize) int srbObjWrite(srbConn *conn, int desc, char *buf, int len) int srbObjClose (srbConn* conn, int desc)
Sput.c – code/* Create a srb file = argv[2] */ out_fd = srbObjCreate (conn, MDAS_CATALOG, argv[2], DATATYPE, RESOURCE , COLLECTION, NULL, -1); in_fd = open (argv[1], O_RDONLY, 0);
Sput.c – (cont)while ((bytesRead = read(in_fd, buf, BUFSIZE)) > 0) { /* Write to the data object */ bytesWritten = srbObjWrite(conn, out_fd, buf, bytesRead); if (bytesWritten < bytesRead) { fprintf(stderr, "Error: Read %d bytes, Wrote %d bytes.\n ", bytesRead, bytesWritten); clFinish (conn); free (buf); exit (1); } total += bytesWritten; } srbObjClose (conn, out_fd);
Sget.c – export a file from SRB to local FSint srbObjOpen(srbConn* conn, char *objID, int oflag, char *collectionName) Int srbObjRead(srbConn *conn, int desc, char *buf, int len)
Sput.c – codein_fd = srbObjOpen (conn, argv[1], O_RDONLY, COLLECTION);out_fd = open (argv[2], O_CREAT|O_WRONLY, 0640);
Sget.c – continuewhile ((bytesRead = srbObjRead (conn, in_fd, buf, BUFSIZE)) > 0) { /* Write to the data object */ bytesWritten = write (out_fd, buf, bytesRead); if (bytesWritten < bytesRead) { . . exit (1); } total += bytesWritten; } srbObjClose (conn, in_fd);
Sreplicate.c – replicate a srb fileintsrbObjReplicate (srbConn* conn, int catType, char objID, char *collectionName,char *newResourceName, char *newPathName)
Sreplicate.c – coderetVal = srbObjReplicate (conn, MDAS_CATALOG, argv[1], COLLECTION, RESOURCE, NULL);Sls –lsrb 0 unix-sdsc 990 2002-10-21-14.33 foo100 srb 1 unix-sdsc 990 2002-10-21-14.33 foo100
sgetcopy.c - Export a replica from srb to local fsint srbObjOpen(srbConn* conn, char *objID, int oflag, char *collectionName) * Additionsl conditions can be appended to the objID. * The char '&‘ – start of condition input. * foo©=1 specifies opening replica number 1 of data object "foo".
sgetcopy.c – codeUsage: sput srb-file repl_num local-filesprintf (objName, "%s©=%-d", argv[1], repl_num);in_fd = srbObjOpen (conn, objName, O_RDONLY, COLLECTION);
Stat.c - get the stat a srb fileUsage: sstat [-r] srb-file int srbObjStat(srbConn* conn, int catType, char *path, struct stat *statbuf)int srbObjUnlink (srbConn* conn, char *objID, char *collectionName)
Stat.c – codesprintf (myPath, "%s/%s", COLLECTION, argv[optind]);retVal = srbObjStat (conn, MDAS_CATALOG, myPath, &statbuf);retVal = srbObjUnlink (conn, argv[optind], COLLECTION);
squery.c - replicate a srb fileint srbGetDataDirInfo (srbConn* conn, int catType, char qval[][MAX_TOKEN], int *selval, mdasC_sql_result_struct *myresult, int rowsWanted)* qval[][] and selval[] array to compose SQL queries* Myresult – out query result
squery.c – code* selval[] array specifies a list of attrbutes to select* qval[][] specifies the lists of predicates for the query* Index of the array define in catalog/include/mdasC_db2_externs.h
Squery.c – (cont1)/* Initialize the selval and qval array. */ for (i = 0; i < MAX_DCS_NUM; i++) { selval[i] = 0; sprintf(qval[i],""); }/* set up the query: Given the Collection, select the * filename, size, resource name, file owner and * the creation timestamp */
Squery.c – (cont2)sprintf(qval[DATA_GRP_NAME]," = '%s'",argv[1]); selval[DATA_NAME] = 1; selval[SIZE] = 1; selval[PHY_RSRC_NAME] = 1; selval[DATA_OWNER] = 1; selval[REPL_TIMESTAMP] = 1; /* Send the query request */ if ((retVal = srbGetDataDirInfo(conn, MDAS_CATALOG, qval, selval, &myresult, ROWS_WANTED)) < 0) {
Squery.c – (cont3) while (myresult.continuation_index >= 0) { if ((retVal = srbGetMoreRows (conn, MDAS_CATALOG, myresult.continuation_index, &myresult, ROWS_WANTED)) < 0) break; /* Dump the result */ printSqlResult (&myresult); clearSqlResult (&myresult); }
Squery.c – (cont4)tab_name=sekar.MDAS_AD_REPL, att_name=data_name values=foo1 values=foo100tab_name=sekar.MDAS_ADC_REPL, att_name=modify_timestamp values=2000-06-28-10.48.15 values=2000-06-28-08.08.30tab_name=sekar.MDAS_AD_REPL, att_name=data_size values=6586 values=131089tab_name=sekar.MDAS_AR_PHYSICAL, att_name=phy_rsrc_name values=unix-sdsc values=unix-sdsctab_name=sekar.MDAS_CD_OWNER_USER, att_name=user_name values=cisuser values=cisuser