removed obsolete scripts

This commit is contained in:
2021-03-17 12:37:16 +01:00
parent cac831bfc6
commit dac52f63f2
8 changed files with 42 additions and 131 deletions

View File

@@ -55,17 +55,18 @@ To upload and start recording of all configured sources use:
_Note:_ Labled sources can be individually stopped and/or restarted by the stop/restart subcommand. A label can be attached to more than one source. While doing so, the restart would affect all sources with the given label.
## Restarting a labeled source
```bash
./bufferutils restart --label <label>
```
## Stopping a labeled source
```bash
./bufferutils stop --label <label>
```
## Restarting a labeled source
```bash
./bufferutils restart --label <label>
```
## Stopping a sources by backend
@@ -75,6 +76,11 @@ Sources of a specific backend can be stopped like this (currently only the "sf-i
./bufferutils stop --backend sf-imagebuffer
```
## Stopping all sources
```bash
./bufferutils stop --all
```

View File

@@ -14,6 +14,7 @@ logging.basicConfig(
base_directory = Path(".")
upload_url = "https://dispatcher-api.psi.ch/sf/configuration/upload"
delete_url = "https://dispatcher-api.psi.ch/sf/configuration/delete"
# upload_url = "http://localhost:1234"
@@ -152,24 +153,30 @@ def read_files(files_dir, file_type):
return {file_type: sources}
def upload_sources_and_policies(sources, policies):
def update_sources_and_policies(sources, policies, update_type="upload"):
"""
Upload sources and policies definition to the data/imagebuffer
Update sources and policies definition to the data/imagebuffer
:param sources: sources to upload
:param policies: policies to upload
:param update_type: update type - upload or delete
:return:
"""
upload_files = [("files", ("all.sources", StringIO(json.dumps(sources)))),
("files", ("all.policies", StringIO(json.dumps(policies))))]
logging.info(f"Upload {len(sources['sources'])} sources and {len(policies['policies'])} policies")
test_response = requests.post(upload_url, files=upload_files)
logging.info(f"Update - {update_type} {len(sources['sources'])} sources and {len(policies['policies'])} policies")
if update_type == "upload":
test_response = requests.post(upload_url, files=upload_files)
elif update_type == "delete":
test_response = requests.post(delete_url, files=upload_files)
else:
logging.error(f"Update type - {update_type} - is not supported")
if test_response.ok:
logging.info("Upload completed successfully!")
logging.info("Update completed successfully!")
else:
logging.error(f"Upload failed!\n{test_response.text}")
logging.error(f"Update failed!\n{test_response.text}")
def update_channel_cache():
@@ -222,6 +229,11 @@ def main():
default=None,
help="backend sources to stop")
parser_stop.add_argument('-a',
'--all',
action="store_true",
help="stop all sources")
parser_list = subparsers.add_parser('list',
help="list",
formatter_class=argparse.RawTextHelpFormatter)
@@ -242,7 +254,7 @@ def main():
# sources = remove_labels(sources)
# print(json.dumps(sources))
upload_sources_and_policies(sources, policies)
update_sources_and_policies(sources, policies)
# Update channels chache
update_channel_cache()
@@ -267,10 +279,10 @@ def main():
sources_new = remove_labeled_source(sources_new, label)
# Stopping the removed source(s)
upload_sources_and_policies(sources_new, policies)
update_sources_and_policies(sources_new, policies)
# Starting the source(s) again
upload_sources_and_policies(sources, policies)
update_sources_and_policies(sources, policies)
# There is no need to update the channel chache as nothing really changed
else:
@@ -296,7 +308,8 @@ def main():
sources_new = remove_labeled_source(sources, label)
# Stopping the removed source(s)
upload_sources_and_policies(sources_new, policies)
update_sources_and_policies(sources_new, policies)
elif arguments.backend:
backend = arguments.backend
if backend != "sf-imagebuffer":
@@ -315,7 +328,14 @@ def main():
sources_new = remove_backend_source(sources, backend)
# Stopping the removed source(s)
upload_sources_and_policies(sources_new, policies)
update_sources_and_policies(sources_new, policies)
elif arguments.all:
policies = read_files(base_directory / Path("policies"), "policies")
sources = read_files(base_directory / Path("sources"), "sources")
logging.info("Stopping all sources")
update_sources_and_policies(sources, policies, update_type="delete")
else:
logging.warning("Not yet implemented")

View File

@@ -1,6 +0,0 @@
#!/bin/bash
rm sources/SARFE.sources
./upload.sh
git stash
./upload.sh

20
stop.sh
View File

@@ -1,20 +0,0 @@
#!/bin/bash
HOST="https://dispatcher-api.psi.ch/sf"
# HOST="http://localhost:8080"
HTTP_ADDRESS="/configuration/delete"
RESPONSE=response.json
# see http://stackoverflow.com/questions/18258804/how-to-catch-timeout-errors-in-a-curl-shell-script
COMMAND="curl -s -w %{http_code} -X POST"
while read -r -d '' filename; do
COMMAND+=" -F files=@${filename}"
done < <(find . \( -name "*.sources" -o -name "*.policies" \) -print0)
COMMAND+=" ${HOST}${HTTP_ADDRESS} -o ${RESPONSE}"
# echo "Execute command: "${COMMAND}
STATUS=$(${COMMAND})
cat ${RESPONSE}
rm -f ${RESPONSE}
#echo ${STATUS}

View File

@@ -1,20 +0,0 @@
#!/bin/bash
HOST="https://dispatcher-api.psi.ch/sf"
# HOST="http://localhost:8080"
HTTP_ADDRESS="/configuration/delete"
RESPONSE=response.json
# see http://stackoverflow.com/questions/18258804/how-to-catch-timeout-errors-in-a-curl-shell-script
COMMAND="curl -s -w %{http_code} -X POST"
while read -r -d '' filename; do
COMMAND+=" -F files=@${filename}"
done < <(find . \( -name "image.sources" -o -name "image.policies" \) -print0)
COMMAND+=" ${HOST}${HTTP_ADDRESS} -o ${RESPONSE}"
# echo "Execute command: "${COMMAND}
STATUS=$(${COMMAND})
cat ${RESPONSE}
rm -f ${RESPONSE}
#echo ${STATUS}

View File

@@ -1,20 +0,0 @@
#!/bin/bash
HOST="https://dispatcher-api.psi.ch/sf"
# HOST="http://localhost:8080"
HTTP_ADDRESS="/configuration/delete"
RESPONSE=response.json
# see http://stackoverflow.com/questions/18258804/how-to-catch-timeout-errors-in-a-curl-shell-script
COMMAND="curl -s -w %{http_code} -X POST"
while read -r -d '' filename; do
COMMAND+=" -F files=@${filename}"
done < <(find . \( -name "timing.sources" -o -name "timing.policies" \) -print0)
COMMAND+=" ${HOST}${HTTP_ADDRESS} -o ${RESPONSE}"
# echo "Execute command: "${COMMAND}
STATUS=$(${COMMAND})
cat ${RESPONSE}
rm -f ${RESPONSE}
#echo ${STATUS}

View File

@@ -1,29 +0,0 @@
#!/bin/bash
HOST="https://dispatcher-api.psi.ch/sf"
# HOST="http://localhost:8080"
HTTP_ADDRESS="/configuration/upload"
RESPONSE=response.json
# see http://stackoverflow.com/questions/18258804/how-to-catch-timeout-errors-in-a-curl-shell-script
COMMAND="curl -s -w %{http_code} -X POST"
while read -r -d '' filename; do
COMMAND+=" -F files=@${filename}"
echo -n "."
done < <(find . \( -name "*.sources" -o -name "*.policies" \) -print0)
echo ""
COMMAND+=" ${HOST}${HTTP_ADDRESS} -o ${RESPONSE}"
# echo "Execute command: "${COMMAND}
STATUS=$(${COMMAND})
if [ -f ${RESPONSE} ]; then
cat ${RESPONSE}
fi
rm -f ${RESPONSE}
#echo ${STATUS}
# Clear/Reload API cache
curl -H "Content-Type: application/json" -d '{"reload": "true"}' https://data-api.psi.ch/sf/channels/config > /dev/null

View File

@@ -1,20 +0,0 @@
#!/bin/bash
HOST="https://dispatcher-api.psi.ch/sf"
# HOST="http://localhost:8080"
HTTP_ADDRESS="/configuration/upload"
RESPONSE=response.json
# see http://stackoverflow.com/questions/18258804/how-to-catch-timeout-errors-in-a-curl-shell-script
COMMAND="curl -s -w %{http_code} -X POST"
while read -r -d '' filename; do
COMMAND+=" -F files=@${filename}"
done < <(find . \( -name "image.sources" -o -name "image.policies" \) -print0)
COMMAND+=" ${HOST}${HTTP_ADDRESS} -o ${RESPONSE}"
# echo "Execute command: "${COMMAND}
STATUS=$(${COMMAND})
cat ${RESPONSE}
rm -f ${RESPONSE}
#echo ${STATUS}