• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/SpiNNaker-comms/src/main/java/uk/ac/manchester/spinnaker/spalloc/SpallocJobAPI.java
1
/*
2
 * Copyright (c) 2018 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.spalloc;
17

18
import static java.net.InetAddress.getByName;
19
import static uk.ac.manchester.spinnaker.machine.ChipLocation.ZERO_ZERO;
20

21
import java.io.IOException;
22
import java.util.ArrayList;
23
import java.util.List;
24

25
import com.google.errorprone.annotations.MustBeClosed;
26

27
import uk.ac.manchester.spinnaker.connections.BootConnection;
28
import uk.ac.manchester.spinnaker.connections.SCPConnection;
29
import uk.ac.manchester.spinnaker.machine.HasChipLocation;
30
import uk.ac.manchester.spinnaker.machine.MachineDimensions;
31
import uk.ac.manchester.spinnaker.machine.MachineVersion;
32
import uk.ac.manchester.spinnaker.spalloc.exceptions.JobDestroyedException;
33
import uk.ac.manchester.spinnaker.spalloc.exceptions.SpallocServerException;
34
import uk.ac.manchester.spinnaker.spalloc.exceptions.SpallocStateChangeTimeoutException;
35
import uk.ac.manchester.spinnaker.spalloc.messages.BoardCoordinates;
36
import uk.ac.manchester.spinnaker.spalloc.messages.BoardPhysicalCoordinates;
37
import uk.ac.manchester.spinnaker.spalloc.messages.Connection;
38
import uk.ac.manchester.spinnaker.spalloc.messages.State;
39
import uk.ac.manchester.spinnaker.transceiver.SpinnmanException;
40
import uk.ac.manchester.spinnaker.transceiver.Transceiver;
41
import uk.ac.manchester.spinnaker.transceiver.TransceiverInterface;
42

43
/** The interface supported by a {@linkplain SpallocJob spalloc job}. */
44
public interface SpallocJobAPI {
45
        /**
46
         * Destroy the job and disconnect from the server.
47
         *
48
         * @throws IOException
49
         *             If communications fail.
50
         * @throws SpallocServerException
51
         *             If the spalloc server rejects the operation request.
52
         * @throws InterruptedException
53
         *             If interrupted while waiting.
54
         */
55
        default void destroy()
56
                        throws IOException, SpallocServerException, InterruptedException {
57
                destroy(null);
×
58
        }
×
59

60
        /**
61
         * Destroy the job and disconnect from the server.
62
         *
63
         * @param reason
64
         *            Gives a human-readable explanation for the destruction of the
65
         *            job.
66
         * @throws IOException
67
         *             If communications fail.
68
         * @throws SpallocServerException
69
         *             If the spalloc server rejects the operation request.
70
         * @throws InterruptedException
71
         *             If interrupted while waiting.
72
         */
73
        void destroy(String reason)
74
                        throws IOException, SpallocServerException, InterruptedException;
75

76
        /**
77
         * Turn the boards allocated to the job on or off.
78
         * <p>
79
         * Does nothing if the job has not yet been allocated any boards.
80
         * <p>
81
         * The {@link #waitUntilReady(Integer)} method may be used to wait for the
82
         * boards to fully turn on or off.
83
         *
84
         * @param powerOn
85
         *            true to power on the boards, false to power off. If the boards
86
         *            are already turned on, setting power to true will reset them.
87
         *            If {@code null}, this method does nothing.
88
         * @throws IOException
89
         *             If communications fail.
90
         * @throws SpallocServerException
91
         *             If the spalloc server rejects the operation request.
92
         * @throws InterruptedException
93
         *             If interrupted while waiting.
94
         */
95
        void setPower(Boolean powerOn)
96
                        throws IOException, SpallocServerException, InterruptedException;
97

98
        /**
99
         * Reset (power-cycle) the boards allocated to the job.
100
         * <p>
101
         * Does nothing if the job has not been allocated.
102
         * <p>
103
         * The {@link #waitUntilReady(Integer)} method may be used to wait for the
104
         * boards to fully turn on or off.
105
         *
106
         * @throws IOException
107
         *             If communications fail.
108
         * @throws SpallocServerException
109
         *             If the spalloc server rejects the operation request.
110
         * @throws InterruptedException
111
         *             If interrupted while waiting.
112
         */
113
        default void reset()
114
                        throws IOException, SpallocServerException, InterruptedException {
115
                setPower(true);
×
116
        }
×
117

118
        /** @return The ID of the job. */
119
        int getID();
120

121
        /**
122
         * @return The current state of the job.
123
         * @throws IOException
124
         *             If communications fail.
125
         * @throws SpallocServerException
126
         *             If the spalloc server rejects the operation request.
127
         * @throws InterruptedException
128
         *             If interrupted while waiting.
129
         */
130
        State getState()
131
                        throws IOException, SpallocServerException, InterruptedException;
132

133
        /**
134
         * @return The current power state of the job.
135
         * @throws IOException
136
         *             If communications fail.
137
         * @throws SpallocServerException
138
         *             If the spalloc server rejects the operation request.
139
         * @throws InterruptedException
140
         *             If interrupted while waiting.
141
         */
142
        Boolean getPower()
143
                        throws IOException, SpallocServerException, InterruptedException;
144

145
        /**
146
         * @return The reason for destruction of the job, or {@code null} if there
147
         *         is no reason (perhaps because the job isn't destroyed). Note that
148
         *         you should use {@link #getState()} to determine if the job is
149
         *         destroyed, not this method.
150
         * @throws IOException
151
         *             If communications fail.
152
         * @throws SpallocServerException
153
         *             If the spalloc server rejects the operation request.
154
         * @throws InterruptedException
155
         *             If interrupted while waiting.
156
         */
157
        String getDestroyReason()
158
                        throws IOException, SpallocServerException, InterruptedException;
159

160
        /**
161
         * @return The list of connections, where each connection says what the
162
         *         hostname is to talk to a particular board's root chip.
163
         * @throws IOException
164
         *             If communications fail.
165
         * @throws SpallocServerException
166
         *             If the spalloc server rejects the operation request.
167
         * @throws IllegalStateException
168
         *             If the spalloc job is not Ready.
169
         * @throws InterruptedException
170
         *             If interrupted while waiting.
171
         */
172
        List<Connection> getConnections() throws IOException,
173
                        SpallocServerException, IllegalStateException, InterruptedException;
174

175
        /**
176
         * Construct a transceiver for talking to this job.
177
         *
178
         * @return A transceiver (or {@code null} if the job is in a state where it
179
         *         can't be talked to at the moment). Uses direct connections. Will
180
         *         be able to boot the allocated boards and talk SCP to them. BMP
181
         *         access will be disabled.
182
         * @throws IOException
183
         *             If communications fail.
184
         * @throws SpallocServerException
185
         *             If the spalloc server rejects the operation request.
186
         * @throws IllegalStateException
187
         *             If the spalloc job is not Ready.
188
         * @throws InterruptedException
189
         *             If interrupted while waiting.
190
         * @throws SpinnmanException
191
         *             If the transceiver creation itself fails.
192
         */
193
        @MustBeClosed
194
        default TransceiverInterface getTransceiver()
195
                        throws IOException, SpallocServerException, IllegalStateException,
196
                        InterruptedException, SpinnmanException {
197
                var ver = MachineVersion.bySize(getDimensions());
×
198
                var connInfo = getConnections();
×
199
                if (connInfo == null) {
×
200
                        return null;
×
201
                }
202
                String bootHost = null;
×
203
                for (var c : connInfo) {
×
204
                        if (c.chip().equals(ZERO_ZERO)) {
×
205
                                bootHost = c.hostname();
×
206
                        }
207
                }
×
208
                if (bootHost == null) {
×
209
                        return null;
×
210
                }
211
                var connections = new ArrayList<
×
212
                                uk.ac.manchester.spinnaker.connections.model.Connection>();
213
                connections.add(new BootConnection(getByName(bootHost), null));
×
214
                for (var c : connInfo) {
×
215
                        connections
×
216
                                        .add(new SCPConnection(c.chip(), getByName(c.hostname())));
×
217
                }
×
218

219
                return new Transceiver(ver, connections);
×
220
        }
221

222
        /**
223
         * @return The name of the host that is the root chip of the whole
224
         *         allocation.
225
         * @throws IOException
226
         *             If communications fail.
227
         * @throws SpallocServerException
228
         *             If the spalloc server rejects the operation request.
229
         * @throws InterruptedException
230
         *             If interrupted while waiting.
231
         */
232
        String getHostname()
233
                        throws IOException, SpallocServerException, InterruptedException;
234

235
        /**
236
         * @return The dimensions of the machine in chips, e.g., for booting.
237
         * @throws IOException
238
         *             If communications fail.
239
         * @throws SpallocServerException
240
         *             If the spalloc server rejects the operation request.
241
         * @throws IllegalStateException
242
         *             If the spalloc job is not Ready.
243
         * @throws InterruptedException
244
         *             If interrupted while waiting.
245
         */
246
        MachineDimensions getDimensions() throws IOException,
247
                        SpallocServerException, IllegalStateException, InterruptedException;
248

249
        /**
250
         * @return The name of the machine the job is allocated on.
251
         * @throws IOException
252
         *             If communications fail.
253
         * @throws SpallocServerException
254
         *             If the spalloc server rejects the operation request.
255
         * @throws IllegalStateException
256
         *             If the spalloc job is not Ready.
257
         * @throws InterruptedException
258
         *             If interrupted while waiting.
259
         */
260
        String getMachineName() throws IOException, SpallocServerException,
261
                        IllegalStateException, InterruptedException;
262

263
        /**
264
         * @return All the boards allocated to the job.
265
         * @throws IOException
266
         *             If communications fail.
267
         * @throws SpallocServerException
268
         *             If the spalloc server rejects the operation request.
269
         * @throws IllegalStateException
270
         *             If the spalloc job is not Ready.
271
         * @throws InterruptedException
272
         *             If interrupted while waiting.
273
         */
274
        List<BoardCoordinates> getBoards() throws IOException,
275
                        SpallocServerException, IllegalStateException, InterruptedException;
276

277
        /**
278
         * Block until the job's state changes from the supplied state.
279
         *
280
         * @param oldState
281
         *            The current state.
282
         * @return The new state.
283
         * @throws SpallocServerException
284
         *             If the spalloc server rejects the operation request.
285
         * @throws InterruptedException
286
         *             If interrupted while waiting.
287
         */
288
        default State waitForStateChange(State oldState)
289
                        throws SpallocServerException, InterruptedException {
290
                return waitForStateChange(oldState, null);
×
291
        }
292

293
        /**
294
         * Block until the job's state changes from the supplied state.
295
         *
296
         * @param oldState
297
         *            The current state.
298
         * @param timeout
299
         *            The number of seconds to wait for a change before timing out.
300
         *            If None, wait forever.
301
         * @return The new state, or old state if timed out.
302
         * @throws SpallocServerException
303
         *             If the spalloc server rejects the operation request.
304
         * @throws InterruptedException
305
         *             If interrupted while waiting.
306
         */
307
        State waitForStateChange(State oldState, Integer timeout)
308
                        throws SpallocServerException, InterruptedException;
309

310
        /**
311
         * Block until the job is allocated and ready.
312
         *
313
         * @param timeout
314
         *            The number of milliseconds to wait before timing out. If None,
315
         *            wait forever.
316
         * @throws IOException
317
         *             If communications fail.
318
         * @throws SpallocServerException
319
         *             If the spalloc server rejects the operation request.
320
         * @throws SpallocStateChangeTimeoutException
321
         *             If the timeout expired before the ready state was entered.
322
         * @throws JobDestroyedException
323
         *             If the job was destroyed before becoming ready.
324
         * @throws InterruptedException
325
         *             If interrupted while waiting.
326
         */
327
        void waitUntilReady(Integer timeout)
328
                        throws JobDestroyedException, IOException, SpallocServerException,
329
                        SpallocStateChangeTimeoutException, InterruptedException;
330

331
        /**
332
         * Locates and returns the physical coordinates containing a given chip in a
333
         * machine allocated to this job.
334
         *
335
         * @param chip
336
         *            The coordinates of the chip
337
         * @return the physical coordinates of the board
338
         * @throws IOException
339
         *             If communications fail.
340
         * @throws SpallocServerException
341
         *             If the spalloc server rejects the operation request.
342
         * @throws InterruptedException
343
         *             If interrupted while waiting.
344
         */
345
        BoardPhysicalCoordinates whereIs(HasChipLocation chip)
346
                        throws IOException, SpallocServerException, InterruptedException;
347
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc