Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nrm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
argo
nrm
Commits
24ddf2db
Commit
24ddf2db
authored
Jul 16, 2018
by
Sridutt Bhalachandra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added c downstream api
parent
c61e07ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
0 deletions
+92
-0
lib/downstream_api.c
lib/downstream_api.c
+61
-0
lib/downstream_api.h
lib/downstream_api.h
+31
-0
No files found.
lib/downstream_api.c
0 → 100644
View file @
24ddf2db
#include "nrm.h"
#include<zmq.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<assert.h>
int
nrm_init
(
struct
nrm_context
*
ctxt
,
const
char
*
uuid
)
{
assert
(
ctxt
!=
NULL
);
assert
(
uuid
!=
NULL
);
char
*
uri
=
getenv
(
NRM_ENV_URI
);
if
(
uri
==
NULL
)
uri
=
NRM_DEFAULT_URI
;
ctxt
->
container_uuid
=
getenv
(
"ARGO_CONTAINER_UUID"
);
assert
(
ctxt
->
container_uuid
!=
NULL
);
ctxt
->
app_uuid
=
(
char
*
)
uuid
;
ctxt
->
context
=
zmq_ctx_new
();
ctxt
->
socket
=
zmq_socket
(
ctxt
->
context
,
ZMQ_PUB
);
int
err
=
zmq_connect
(
ctxt
->
socket
,
uri
);
assert
(
err
==
0
);
char
buf
[
512
];
snprintf
(
buf
,
512
,
NRM_START_FORMAT
,
ctxt
->
container_uuid
,
ctxt
->
app_uuid
);
sleep
(
1
);
err
=
zmq_send
(
ctxt
->
socket
,
buf
,
strnlen
(
buf
,
512
),
0
);
assert
(
err
>
0
);
assert
(
!
clock_gettime
(
CLOCK_REALTIME
,
&
ctxt
->
time
));
ctxt
->
acc
=
0
;
return
0
;
}
int
nrm_fini
(
struct
nrm_context
*
ctxt
)
{
assert
(
ctxt
!=
NULL
);
char
buf
[
512
];
snprintf
(
buf
,
512
,
NRM_EXIT_FORMAT
,
ctxt
->
app_uuid
);
int
err
=
zmq_send
(
ctxt
->
socket
,
buf
,
strnlen
(
buf
,
512
),
0
);
assert
(
err
>
0
);
zmq_close
(
ctxt
->
socket
);
zmq_ctx_destroy
(
ctxt
->
context
);
return
0
;
}
int
nrm_send_progress
(
struct
nrm_context
*
ctxt
,
unsigned
long
progress
)
{
char
buf
[
512
];
struct
timespec
now
;
clock_gettime
(
CLOCK_REALTIME
,
&
now
);
long
long
int
timediff
=
(
now
.
tv_nsec
-
ctxt
->
time
.
tv_nsec
)
+
1e9
*
(
now
.
tv_sec
-
ctxt
->
time
.
tv_sec
);
ctxt
->
acc
+=
progress
;
if
(
timediff
>
NRM_RATELIMIT_THRESHOLD
)
{
snprintf
(
buf
,
512
,
NRM_PROGRESS_FORMAT
,
ctxt
->
acc
,
ctxt
->
app_uuid
);
int
err
=
zmq_send
(
ctxt
->
socket
,
buf
,
strnlen
(
buf
,
512
),
0
);
assert
(
err
>
0
);
ctxt
->
acc
=
0
;
}
ctxt
->
time
=
now
;
return
0
;
}
lib/downstream_api.h
0 → 100644
View file @
24ddf2db
#ifndef NRM_H
#define NRM_H 1
#include<time.h>
/* min time in nsec between messages: necessary for rate-limiting progress
* report. For now, 10ms is the threashold. */
#define NRM_RATELIMIT_THRESHOLD (10000000LL)
struct
nrm_context
{
void
*
context
;
void
*
socket
;
char
*
container_uuid
;
char
*
app_uuid
;
struct
timespec
time
;
unsigned
long
acc
;
};
#define NRM_DEFAULT_URI "ipc:///tmp/nrm-downstream-in"
#define NRM_ENV_URI "ARGO_NRM_DOWNSTREAM_IN_URI"
#define NRM_START_FORMAT "{\"type\":\"application\", \"event\":\"start\", \"container\": \"%s\", \"uuid\": \"%s\", \"progress\": true, \"threads\": null}"
#define NRM_PROGRESS_FORMAT "{\"type\":\"application\", \"event\":\"progress\", \"payload\": \"%lu\", \"uuid\": \"%s\"}"
#define NRM_EXIT_FORMAT "{\"type\":\"application\", \"event\":\"exit\", \"uuid\": \"%s\"}"
int
nrm_init
(
struct
nrm_context
*
,
const
char
*
);
int
nrm_fini
(
struct
nrm_context
*
);
int
nrm_send_progress
(
struct
nrm_context
*
,
unsigned
long
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment