Skip to content

Commit 17c4d2a

Browse files
author
Jamie Hannaford
committed
first attempt at DLO support
1 parent c2e53d2 commit 17c4d2a

File tree

5 files changed

+437
-245
lines changed

5 files changed

+437
-245
lines changed

src/ObjectStore/v1/Api.php

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Api extends AbstractApi
88
{
99
public function __construct()
1010
{
11-
$this->params = new Params();
11+
$this->params = new Params;
1212
}
1313

1414
public function getAccount()
@@ -17,13 +17,13 @@ public function getAccount()
1717
'method' => 'GET',
1818
'path' => '',
1919
'params' => [
20-
'format' => $this->params->format,
20+
'format' => $this->params->format(),
2121
'limit' => $this->params->limit(),
2222
'marker' => $this->params->marker(),
23-
'endMarker' => $this->params->endMarker,
24-
'prefix' => $this->params->prefix,
25-
'delimiter' => $this->params->delimiter,
26-
'newest' => $this->params->newest,
23+
'endMarker' => $this->params->endMarker(),
24+
'prefix' => $this->params->prefix(),
25+
'delimiter' => $this->params->delimiter(),
26+
'newest' => $this->params->newest(),
2727
],
2828
];
2929
}
@@ -57,15 +57,15 @@ public function getContainer()
5757
'method' => 'GET',
5858
'path' => '{name}',
5959
'params' => [
60-
'name' => $this->params->containerName,
61-
'format' => $this->params->format,
60+
'name' => $this->params->containerName(),
61+
'format' => $this->params->format(),
6262
'limit' => $this->params->limit(),
6363
'marker' => $this->params->marker(),
64-
'endMarker' => $this->params->endMarker,
65-
'prefix' => $this->params->prefix,
66-
'path' => $this->params->path,
67-
'delimiter' => $this->params->delimiter,
68-
'newest' => $this->params->newest,
64+
'endMarker' => $this->params->endMarker(),
65+
'prefix' => $this->params->prefix(),
66+
'path' => $this->params->path(),
67+
'delimiter' => $this->params->delimiter(),
68+
'newest' => $this->params->newest(),
6969
],
7070
];
7171
}
@@ -76,17 +76,17 @@ public function putContainer()
7676
'method' => 'PUT',
7777
'path' => '{name}',
7878
'params' => [
79-
'name' => $this->params->containerName,
79+
'name' => $this->params->containerName(),
8080
'readAccess' => $this->params->readAccess('container'),
8181
'writeAccess' => $this->params->writeAccess('container'),
8282
'metadata' => $this->params->metadata('container'),
8383
'syncTo' => $this->params->syncTo(),
8484
'syncKey' => $this->params->syncKey(),
85-
'versionsLocation' => $this->params->versionsLocation,
86-
'bytesQuota' => $this->params->bytesQuota,
87-
'countQuota' => $this->params->countQuota,
88-
'webDirectoryType' => $this->params->webDirType,
89-
'detectContentType' => $this->params->detectContentType,
85+
'versionsLocation' => $this->params->versionsLocation(),
86+
'bytesQuota' => $this->params->bytesQuota(),
87+
'countQuota' => $this->params->countQuota(),
88+
'webDirectoryType' => $this->params->webDirType(),
89+
'detectContentType' => $this->params->detectContentType(),
9090
],
9191
];
9292
}
@@ -97,7 +97,7 @@ public function deleteContainer()
9797
'method' => 'DELETE',
9898
'path' => '{name}',
9999
'params' => [
100-
'name' => $this->params->containerName,
100+
'name' => $this->params->containerName(),
101101
],
102102
];
103103
}
@@ -108,19 +108,19 @@ public function postContainer()
108108
'method' => 'POST',
109109
'path' => '{name}',
110110
'params' => [
111-
'name' => $this->params->containerName,
111+
'name' => $this->params->containerName(),
112112
'readAccess' => $this->params->readAccess('container'),
113113
'writeAccess' => $this->params->writeAccess('container'),
114114
'metadata' => $this->params->metadata('container'),
115115
'removeMetadata' => $this->params->metadata('container', true),
116116
'syncTo' => $this->params->syncTo(),
117117
'syncKey' => $this->params->syncKey(),
118-
'versionsLocation' => $this->params->versionsLocation,
119-
'removeVersionsLocation' => $this->params->removeVersionsLocation,
120-
'bytesQuota' => $this->params->bytesQuota,
121-
'countQuota' => $this->params->countQuota,
122-
'webDirectoryType' => $this->params->webDirType,
123-
'detectContentType' => $this->params->detectContentType,
118+
'versionsLocation' => $this->params->versionsLocation(),
119+
'removeVersionsLocation' => $this->params->removeVersionsLocation(),
120+
'bytesQuota' => $this->params->bytesQuota(),
121+
'countQuota' => $this->params->countQuota(),
122+
'webDirectoryType' => $this->params->webDirType(),
123+
'detectContentType' => $this->params->detectContentType(),
124124
],
125125
];
126126
}
@@ -130,23 +130,23 @@ public function headContainer()
130130
return [
131131
'method' => 'HEAD',
132132
'path' => '{name}',
133-
'params' => ['name' => $this->params->containerName],
133+
'params' => ['name' => $this->params->containerName()],
134134
];
135135
}
136136

137137
public function getObject()
138138
{
139139
return [
140140
'method' => 'GET',
141-
'path' => '{containerName}/{name}',
141+
'path' => '{containerName}/{+name}',
142142
'params' => [
143-
'containerName' => $this->params->containerName,
144-
'name' => $this->params->objectName,
145-
'range' => $this->params->range,
146-
'ifMatch' => $this->params->ifMatch,
147-
'ifNoneMatch' => $this->params->ifNoneMatch,
148-
'ifModifiedSince' => $this->params->ifModifiedSince,
149-
'ifUnmodifiedSince' => $this->params->ifUnmodifiedSince,
143+
'containerName' => $this->params->containerName(),
144+
'name' => $this->params->objectName(),
145+
'range' => $this->params->range(),
146+
'ifMatch' => $this->params->ifMatch(),
147+
'ifNoneMatch' => $this->params->ifNoneMatch(),
148+
'ifModifiedSince' => $this->params->ifModifiedSince(),
149+
'ifUnmodifiedSince' => $this->params->ifUnmodifiedSince(),
150150
],
151151
];
152152
}
@@ -155,21 +155,23 @@ public function putObject()
155155
{
156156
return [
157157
'method' => 'PUT',
158-
'path' => '{containerName}/{name}',
158+
'path' => '{containerName}/{+name}',
159159
'params' => [
160-
'containerName' => $this->params->containerName,
161-
'name' => $this->params->objectName,
162-
'content' => $this->params->content,
163-
'contentType' => $this->params->contentType,
164-
'detectContentType' => $this->params->detectContentType,
165-
'copyFrom' => $this->params->copyFrom,
166-
'ETag' => $this->params->etag,
167-
'contentDisposition' => $this->params->contentDisposition,
168-
'contentEncoding' => $this->params->contentEncoding,
169-
'deleteAt' => $this->params->deleteAt,
170-
'deleteAfter' => $this->params->deleteAfter,
160+
'containerName' => $this->params->containerName(),
161+
'name' => $this->params->objectName(),
162+
'content' => $this->params->content(),
163+
'stream' => $this->params->stream(),
164+
'contentType' => $this->params->contentType(),
165+
'detectContentType' => $this->params->detectContentType(),
166+
'copyFrom' => $this->params->copyFrom(),
167+
'ETag' => $this->params->etag(),
168+
'contentDisposition' => $this->params->contentDisposition(),
169+
'contentEncoding' => $this->params->contentEncoding(),
170+
'deleteAt' => $this->params->deleteAt(),
171+
'deleteAfter' => $this->params->deleteAfter(),
171172
'metadata' => $this->params->metadata('object'),
172-
'ifNoneMatch' => $this->params->ifNoneMatch,
173+
'ifNoneMatch' => $this->params->ifNoneMatch(),
174+
'objectManifest' => $this->params->objectManifest(),
173175
],
174176
];
175177
}
@@ -178,16 +180,16 @@ public function copyObject()
178180
{
179181
return [
180182
'method' => 'COPY',
181-
'path' => '{containerName}/{name}',
183+
'path' => '{containerName}/{+name}',
182184
'params' => [
183-
'containerName' => $this->params->containerName,
184-
'name' => $this->params->objectName,
185-
'destination' => $this->params->destination,
186-
'contentType' => $this->params->contentType,
187-
'contentDisposition' => $this->params->contentDisposition,
188-
'contentEncoding' => $this->params->contentEncoding,
185+
'containerName' => $this->params->containerName(),
186+
'name' => $this->params->objectName(),
187+
'destination' => $this->params->destination(),
188+
'contentType' => $this->params->contentType(),
189+
'contentDisposition' => $this->params->contentDisposition(),
190+
'contentEncoding' => $this->params->contentEncoding(),
189191
'metadata' => $this->params->metadata('object'),
190-
'freshMetadata' => $this->params->freshMetadata,
192+
'freshMetadata' => $this->params->freshMetadata(),
191193
],
192194
];
193195
}
@@ -196,10 +198,10 @@ public function deleteObject()
196198
{
197199
return [
198200
'method' => 'DELETE',
199-
'path' => '{containerName}/{name}',
201+
'path' => '{containerName}/{+name}',
200202
'params' => [
201-
'containerName' => $this->params->containerName,
202-
'name' => $this->params->objectName,
203+
'containerName' => $this->params->containerName(),
204+
'name' => $this->params->objectName(),
203205
],
204206
];
205207
}
@@ -208,10 +210,10 @@ public function headObject()
208210
{
209211
return [
210212
'method' => 'HEAD',
211-
'path' => '{containerName}/{name}',
213+
'path' => '{containerName}/{+name}',
212214
'params' => [
213-
'containerName' => $this->params->containerName,
214-
'name' => $this->params->objectName,
215+
'containerName' => $this->params->containerName(),
216+
'name' => $this->params->objectName(),
215217
],
216218
];
217219
}
@@ -220,18 +222,18 @@ public function postObject()
220222
{
221223
return [
222224
'method' => 'POST',
223-
'path' => '{containerName}/{name}',
225+
'path' => '{containerName}/{+name}',
224226
'params' => [
225-
'containerName' => $this->params->containerName,
226-
'name' => $this->params->objectName,
227+
'containerName' => $this->params->containerName(),
228+
'name' => $this->params->objectName(),
227229
'metadata' => $this->params->metadata('object'),
228230
'removeMetadata' => $this->params->metadata('object', true),
229-
'deleteAt' => $this->params->deleteAt,
230-
'deleteAfter' => $this->params->deleteAfter,
231-
'contentDisposition' => $this->params->contentDisposition,
232-
'contentEncoding' => $this->params->contentEncoding,
233-
'contentType' => $this->params->contentType,
234-
'detectContentType' => $this->params->detectContentType,
231+
'deleteAt' => $this->params->deleteAt(),
232+
'deleteAfter' => $this->params->deleteAfter(),
233+
'contentDisposition' => $this->params->contentDisposition(),
234+
'contentEncoding' => $this->params->contentEncoding(),
235+
'contentType' => $this->params->contentType(),
236+
'detectContentType' => $this->params->detectContentType(),
235237
],
236238
];
237239
}

src/ObjectStore/v1/Models/Container.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace OpenStack\ObjectStore\v1\Models;
44

5+
use GuzzleHttp\Promise\Promise;
6+
use GuzzleHttp\Psr7\LimitStream;
57
use Psr\Http\Message\ResponseInterface;
68
use OpenStack\Common\Error\BadResponseError;
79
use OpenStack\Common\Resource\AbstractResource;
@@ -179,4 +181,45 @@ public function createObject(array $data)
179181
{
180182
return $this->model(Object::class)->create($data + ['containerName' => $this->name]);
181183
}
182-
}
184+
185+
/**
186+
* @param array $data
187+
*/
188+
public function createLargeObject(array $data)
189+
{
190+
/** @var \Psr\Http\Message\StreamInterface $stream */
191+
$stream = $data['stream'];
192+
193+
$segmentSize = isset($data['segmentSize']) ? $data['segmentSize'] : 1073741824;
194+
$segmentContainer = isset($data['segmentContainer']) ? $data['segmentContainer'] : $this->name . '_segments';
195+
$segmentPrefix = isset($data['segmentPrefix'])
196+
? $data['segmentPrefix']
197+
: sprintf("%s/%s/%d", $data['name'], microtime(true), $stream->getSize());
198+
199+
/** @var \OpenStack\ObjectStore\v1\Service $service */
200+
$service = $this->getService();
201+
if (!$service->containerExists($segmentContainer)) {
202+
$service->createContainer(['name' => $segmentContainer]);
203+
}
204+
205+
$promises = [];
206+
$count = 0;
207+
208+
while (!$stream->eof() && $count < round($stream->getSize() / $segmentSize)) {
209+
$promises[] = $this->model(Object::class)->createAsync([
210+
'name' => sprintf("%s/%d", $segmentPrefix, ++$count),
211+
'stream' => new LimitStream($stream, $segmentSize, ($count - 1) * $segmentSize),
212+
'containerName' => $segmentContainer,
213+
]);
214+
}
215+
216+
/** @var Promise $p */
217+
$p = \GuzzleHttp\Promise\all($promises);
218+
$p->wait();
219+
220+
return $this->createObject([
221+
'name' => $data['name'],
222+
'objectManifest' => sprintf("%s/%s", $segmentContainer, $segmentPrefix),
223+
]);
224+
}
225+
}

0 commit comments

Comments
 (0)