Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/Operations/StorePeerOperation.cpp @ 5117:849000df79b6
fix missing handling of StoreStatus_StorageFull
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Dec 2022 15:32:53 +0100 |
parents | 6eff25f70121 |
children | 0ea402b4d901 |
rev | line source |
---|---|
2605 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2605 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
2641 | 23 #include "../../PrecompiledHeadersServer.h" |
2605 | 24 #include "StorePeerOperation.h" |
25 | |
26 #include "DicomInstanceOperationValue.h" | |
27 | |
4045 | 28 #include "../../../../OrthancFramework/Sources/Logging.h" |
29 #include "../../../../OrthancFramework/Sources/OrthancException.h" | |
30 #include "../../../../OrthancFramework/Sources/HttpClient.h" | |
31 #include "../../../../OrthancFramework/Sources/SerializationToolbox.h" | |
2605 | 32 |
33 namespace Orthanc | |
34 { | |
35 void StorePeerOperation::Apply(JobOperationValues& outputs, | |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
36 const IJobOperationValue& input) |
2605 | 37 { |
38 // Configure the HTTP client | |
39 HttpClient client(peer_, "instances"); | |
40 client.SetMethod(HttpMethod_Post); | |
41 | |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
42 if (input.GetType() != IJobOperationValue::Type_DicomInstance) |
2605 | 43 { |
44 throw OrthancException(ErrorCode_BadParameterType); | |
45 } | |
46 | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
47 const DicomInstanceOperationValue& instance = |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
48 dynamic_cast<const DicomInstanceOperationValue&>(input); |
2605 | 49 |
50 LOG(INFO) << "Lua: Sending instance " << instance.GetId() << " to Orthanc peer \"" | |
51 << peer_.GetUrl() << "\""; | |
52 | |
53 try | |
54 { | |
4650
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
55 // Lifetime of "body" must exceed the call to "client.Apply()" because of "SetExternalBody()" |
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
56 std::string body; |
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
57 instance.ReadDicom(body); |
2605 | 58 |
4650
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
59 client.SetExternalBody(body); // Avoids a memcpy() |
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
60 |
2605 | 61 std::string answer; |
62 if (!client.Apply(answer)) | |
63 { | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
64 LOG(ERROR) << "Lua: Unable to send instance " << instance.GetId() |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
65 << " to Orthanc peer \"" << peer_.GetUrl(); |
2605 | 66 } |
67 } | |
68 catch (OrthancException& e) | |
69 { | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
70 LOG(ERROR) << "Lua: Unable to send instance " << instance.GetId() |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
71 << " to Orthanc peer \"" << peer_.GetUrl() << "\": " << e.What(); |
2605 | 72 } |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
73 |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
74 outputs.Append(input.Clone()); |
2605 | 75 } |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
76 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
77 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
78 void StorePeerOperation::Serialize(Json::Value& result) const |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
79 { |
2654 | 80 result = Json::objectValue; |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
81 result["Type"] = "StorePeer"; |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
82 peer_.Serialize(result["Peer"], |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
83 true /* force advanced format */, |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
84 true /* include passwords */); |
2655 | 85 } |
86 | |
87 | |
88 StorePeerOperation::StorePeerOperation(const Json::Value& serialized) | |
89 { | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
90 if (SerializationToolbox::ReadString(serialized, "Type") != "StorePeer" || |
2655 | 91 !serialized.isMember("Peer")) |
92 { | |
93 throw OrthancException(ErrorCode_BadFileFormat); | |
94 } | |
95 | |
96 peer_ = WebServiceParameters(serialized["Peer"]); | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
97 } |
2605 | 98 } |