Skip to content

Commit b6f6581

Browse files
authored
Merge pull request #16619 from iterate-ch/bugfix/GH-16618
Review scheduled operations for OpenStack Swift
2 parents cb28de6 + 4b891df commit b6f6581

File tree

5 files changed

+43
-17
lines changed

5 files changed

+43
-17
lines changed

core/src/main/java/ch/cyberduck/core/features/Scheduler.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import ch.cyberduck.core.PasswordCallback;
1919

20+
import org.apache.commons.lang3.concurrent.ConcurrentUtils;
21+
2022
import java.util.concurrent.Future;
2123

2224
@Optional
@@ -35,4 +37,21 @@ public interface Scheduler<R> {
3537
* Shutdown thread pool
3638
*/
3739
void shutdown(boolean gracefully);
40+
41+
Scheduler noop = new Scheduler() {
42+
@Override
43+
public Future repeat(final PasswordCallback callback) {
44+
return ConcurrentUtils.constantFuture(null);
45+
}
46+
47+
@Override
48+
public Future execute(final PasswordCallback callback) {
49+
return ConcurrentUtils.constantFuture(null);
50+
}
51+
52+
@Override
53+
public void shutdown(final boolean gracefully) {
54+
//
55+
}
56+
};
3857
}

defaults/src/main/resources/default.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ openstack.authentication.context=/v2.0/tokens
407407
openstack.metadata.default=
408408
openstack.list.container.limit=100
409409
openstack.list.object.limit=10000
410+
# Preload account info after connect and create X-Account-Meta-Temp-URL-Key if missing in account metadata
410411
openstack.account.preload=true
411412
openstack.cdn.preload=true
412413
openstack.container.size.preload=true
@@ -426,8 +427,6 @@ openstack.upload.largeobject.size.minimum=1048576
426427
openstack.upload.largeobject.cleanup=true
427428
openstack.delete.multiple.partition=10000
428429
openstack.delete.largeobject.segments=true
429-
# Preload account info after connect and create X-Account-Meta-Temp-URL-Key if missing in account metadata
430-
openstack.accounts.preload=true
431430

432431
googledrive.list.limit=1000
433432
googledrive.teamdrive.enable=true

openstack/src/main/java/ch/cyberduck/core/openstack/SwiftAccountLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
import java.io.IOException;
3030
import java.util.Collections;
31+
import java.util.HashMap;
3132
import java.util.Map;
32-
import java.util.concurrent.ConcurrentHashMap;
3333

3434
import ch.iterate.openstack.swift.exception.GenericException;
3535
import ch.iterate.openstack.swift.model.AccountInfo;
@@ -46,7 +46,7 @@ public SwiftAccountLoader(final SwiftSession session) {
4646

4747
@Override
4848
protected Map<Region, AccountInfo> operate(final PasswordCallback callback) throws BackgroundException {
49-
final Map<Region, AccountInfo> accounts = new ConcurrentHashMap<>();
49+
final Map<Region, AccountInfo> accounts = new HashMap<>();
5050
for(Region region : session.getClient().getRegions()) {
5151
try {
5252
final AccountInfo info = session.getClient().getAccountInfo(region);

openstack/src/main/java/ch/cyberduck/core/openstack/SwiftDistributionConfigurationLoader.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
import org.apache.logging.log4j.Logger;
3131

3232
import java.util.Collections;
33-
import java.util.LinkedHashSet;
33+
import java.util.HashMap;
34+
import java.util.HashSet;
35+
import java.util.Map;
3436
import java.util.Set;
3537

3638
/**
3739
* Preload CDN configuration
3840
*/
39-
public class SwiftDistributionConfigurationLoader extends OneTimeSchedulerFeature<Set<Distribution>> {
41+
public class SwiftDistributionConfigurationLoader extends OneTimeSchedulerFeature<Map<Path, Set<Distribution>>> {
4042
private static final Logger log = LogManager.getLogger(SwiftDistributionConfigurationLoader.class);
4143

4244
private final SwiftSession session;
@@ -46,19 +48,19 @@ public SwiftDistributionConfigurationLoader(final SwiftSession session) {
4648
}
4749

4850
@Override
49-
protected Set<Distribution> operate(final PasswordCallback callback) throws BackgroundException {
51+
protected Map<Path, Set<Distribution>> operate(final PasswordCallback callback) throws BackgroundException {
5052
final DistributionConfiguration feature = session.getFeature(DistributionConfiguration.class);
5153
if(null == feature) {
52-
return Collections.emptySet();
54+
return Collections.emptyMap();
5355
}
5456
final AttributedList<Path> containers = new SwiftContainerListService(session,
5557
new SwiftLocationFeature.SwiftRegion(session.getHost().getRegion())).list(Home.ROOT, new DisabledListProgressListener());
56-
final Set<Distribution> distributions = new LinkedHashSet<>();
58+
final Map<Path, Set<Distribution>> distributions = new HashMap<>();
5759
for(Path container : containers) {
5860
for(Distribution.Method method : feature.getMethods(container)) {
5961
final Distribution distribution = feature.read(container, method, new DisabledLoginCallback());
6062
log.info("Cache distribution {}", distribution);
61-
distributions.add(distribution);
63+
distributions.getOrDefault(container, new HashSet<>()).add(distribution);
6264
}
6365
}
6466
return distributions;

openstack/src/main/java/ch/cyberduck/core/openstack/SwiftSession.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,28 @@ public class SwiftSession extends HttpSession<Client> {
6666
= new SwiftRegionService(this);
6767

6868
private final Map<Region, AccountInfo> accounts = new ConcurrentHashMap<>();
69+
private final Map<Path, Set<Distribution>> distributions = new ConcurrentHashMap<>();
6970

7071
private final DelegatingSchedulerFeature scheduler = new DelegatingSchedulerFeature(
71-
new SwiftAccountLoader(this) {
72+
new HostPreferences(host).getBoolean("openstack.account.preload") ? new SwiftAccountLoader(this) {
7273
@Override
7374
protected Map<Region, AccountInfo> operate(final PasswordCallback callback) throws BackgroundException {
7475
final Map<Region, AccountInfo> result = super.operate(callback);
7576
// Only executed single time
7677
accounts.putAll(result);
7778
return result;
7879
}
79-
}, new SwiftDistributionConfigurationLoader(this)
80+
} : Scheduler.noop,
81+
new HostPreferences(host).getBoolean("openstack.cdn.preload") ? new SwiftDistributionConfigurationLoader(this) {
82+
@Override
83+
protected Map<Path, Set<Distribution>> operate(final PasswordCallback callback) throws BackgroundException {
84+
final Map<Path, Set<Distribution>> result = super.operate(callback);
85+
// Only executed single time
86+
distributions.putAll(result);
87+
return result;
88+
}
89+
} : Scheduler.noop
8090
);
81-
private final Map<Path, Set<Distribution>> distributions = new ConcurrentHashMap<>();
8291

8392
public SwiftSession(final Host host, final X509TrustManager trust, final X509KeyManager key) {
8493
super(host, trust, key);
@@ -210,10 +219,7 @@ public Distribution read(final Path container, final Distribution.Method method,
210219
return (T) new SwiftAttributesFinderFeature(this, regionService);
211220
}
212221
if(type == Scheduler.class) {
213-
if(new HostPreferences(host).getBoolean("openstack.accounts.preload")) {
214-
return (T) scheduler;
215-
}
216-
return null;
222+
return (T) scheduler;
217223
}
218224
return super._getFeature(type);
219225
}

0 commit comments

Comments
 (0)