Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 67fd3e0

Browse files
committed
Check free space on disk before download the file
1 parent 27a5969 commit 67fd3e0

File tree

9 files changed

+52
-11
lines changed

9 files changed

+52
-11
lines changed

ddiclient-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
group 'com.kynetics.updatefactory'
12-
version '0.4.6'
12+
version '0.4.7'
1313

1414
apply plugin: 'java'
1515
apply plugin: 'maven'

ddiclient-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
group 'com.kynetics.updatefactory'
12-
version '0.4.6'
12+
version '0.4.7'
1313

1414
apply plugin: 'java'
1515
apply plugin: 'maven'

ddiclient-core/src/main/java/com/kynetics/updatefactory/ddiclient/core/UFService.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,22 @@ private void handlerState(AbstractState currentState, long forceDelay){
229229
break;
230230
case UPDATE_DOWNLOAD:
231231
final UpdateDownloadState updateDownloadState = (UpdateDownloadState) currentState;
232-
callToAbort = client.downloadArtifact(
233-
tenant,
234-
controllerId,
235-
updateDownloadState.getFileInfo().getLinkInfo().getSoftwareModules(),
236-
updateDownloadState.getFileInfo().getLinkInfo().getFileName());
237-
execute(callToAbort, new DownloadArtifact(updateDownloadState), forceDelay);
232+
long spaceNeeded = 0;
233+
for(int i = updateDownloadState.getNextFileToDownload(); i<updateDownloadState.getFileInfoList().size(); i++){
234+
spaceNeeded += updateDownloadState.getFileInfoList().get(i).getSize();
235+
}
236+
237+
if(systemOperation.checkSpace(spaceNeeded)){
238+
callToAbort = client.downloadArtifact(
239+
tenant,
240+
controllerId,
241+
updateDownloadState.getFileInfo().getLinkInfo().getSoftwareModules(),
242+
updateDownloadState.getFileInfo().getLinkInfo().getFileName());
243+
execute(callToAbort, new DownloadArtifact(updateDownloadState), forceDelay);
244+
} else {
245+
onEvent(new InsufficientSpaceEvent());
246+
}
247+
238248
break;
239249
case UPDATE_READY:
240250
final Call checkCancellation = client.getControllerBase(tenant, controllerId);

ddiclient-core/src/main/java/com/kynetics/updatefactory/ddiclient/core/model/event/AbstractEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public abstract class AbstractEvent implements Serializable{
2222
public enum EventName{
2323
SLEEP_REQUEST, UPDATE_CONFIG_REQUEST, SUCCESS, FAILURE, ERROR, UPDATE_FOUND, DOWNLOAD_REQUEST, DOWNLOAD_STARTED,
2424
FILE_CORRUPTED, CANCEL, UPDATE_ERROR, AUTHORIZATION_GRANTED, AUTHORIZATION_DENIED, RESUME, DOWNLOAD_PENDING,
25-
FORCE_CANCEL, AUTHORIZATION_PENDING
25+
FORCE_CANCEL, AUTHORIZATION_PENDING, INSUFFICIENT_SPACE
2626
}
2727

2828
private final EventName eventName;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright © 2017-2019 Kynetics LLC
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
*/
10+
11+
package com.kynetics.updatefactory.ddiclient.core.model.event;
12+
13+
import static com.kynetics.updatefactory.ddiclient.core.model.event.AbstractEvent.EventName.INSUFFICIENT_SPACE;
14+
15+
/**
16+
* @author Daniele Sergio
17+
*/
18+
public class InsufficientSpaceEvent extends AbstractEvent {
19+
public InsufficientSpaceEvent() {
20+
super(INSUFFICIENT_SPACE);
21+
}
22+
}

ddiclient-core/src/main/java/com/kynetics/updatefactory/ddiclient/core/model/state/UpdateDownloadState.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public AbstractState onEvent(AbstractEvent event) {
4343
switch (event.getEventName()) {
4444
case DOWNLOAD_STARTED:
4545
return new SavingFileState(getActionId(), isForced(), getFileInfoList(), getNextFileToDownload(), getLastHash(), ((DownloadStartedEvent) event).getInputStream());
46-
default:
46+
case INSUFFICIENT_SPACE:
47+
return new UpdateEndedState(getActionId(), false, new String[]{"Not enough space"});
48+
default:
4749
return super.onEvent(event);
4850
}
4951
}

ddiclient-core/src/main/java/com/kynetics/updatefactory/ddiclient/core/servicecallback/SystemOperation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public interface SystemOperation {
2424

2525
UpdateStatus updateStatus();
2626

27+
boolean checkSpace(long spaceNeeded);
28+
2729
class UpdateStatus{
2830
private final StatusName statusName;
2931
private final String[] messages;

ddiclient-example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
group 'com.kynetics.updatefactory'
12-
version '0.4.6'
12+
version '0.4.7'
1313
apply plugin: 'java'
1414

1515
sourceCompatibility = 1.8

ddiclient-example/src/main/java/com/kynetics/updatefactory/ddiclient/example/callback/SystemOperationMock.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ public void executeUpdate(long actionId) {
4949
public UpdateStatus updateStatus() {
5050
return status;
5151
}
52+
53+
@Override
54+
public boolean checkSpace(long spaceNeeded) {
55+
return true;
56+
}
5257
}

0 commit comments

Comments
 (0)