~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/instancepoller/updater.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package instancepoller
5
5
 
6
6
import (
7
 
        "fmt"
8
7
        "time"
9
8
 
10
9
        "github.com/juju/errors"
182
181
                        return err
183
182
                }
184
183
 
185
 
                machineStatus := status.StatusPending
 
184
                machineStatus := status.Pending
186
185
                if err == nil {
187
186
                        if statusInfo, err := m.Status(); err != nil {
188
187
                                logger.Warningf("cannot get current machine status for machine %v: %v", m.Id(), err)
194
193
 
195
194
                // the extra condition below (checking allocating/pending) is here to improve user experience
196
195
                // without it the instance status will say "pending" for +10 minutes after the agent comes up to "started"
197
 
                if instInfo.status.Status != status.StatusAllocating && instInfo.status.Status != status.StatusPending {
198
 
                        if len(instInfo.addresses) > 0 && machineStatus == status.StatusStarted {
 
196
                if instInfo.status.Status != status.Allocating && instInfo.status.Status != status.Pending {
 
197
                        if len(instInfo.addresses) > 0 && machineStatus == status.Started {
199
198
                                // We've got at least one address and a status and instance is started, so poll infrequently.
200
199
                                pollInterval = LongPoll
201
200
                        } else if pollInterval < LongPoll {
240
239
        instId, err := m.InstanceId()
241
240
        // We can't ask the machine for its addresses if it isn't provisioned yet.
242
241
        if params.IsCodeNotProvisioned(err) {
243
 
                return instInfo, err
 
242
                return instanceInfo{}, err
244
243
        }
245
244
        if err != nil {
246
 
                return instInfo, fmt.Errorf("cannot get machine's instance id: %v", err)
 
245
                return instanceInfo{}, errors.Annotate(err, "cannot get machine's instance id")
247
246
        }
248
247
        instInfo, err = context.instanceInfo(instId)
249
248
        if err != nil {
250
249
                // TODO (anastasiamac 2016-02-01) This does not look like it needs to be removed now.
251
250
                if params.IsCodeNotImplemented(err) {
252
 
                        return instInfo, err
 
251
                        return instanceInfo{}, err
253
252
                }
254
253
                logger.Warningf("cannot get instance info for instance %q: %v", instId, err)
255
254
                return instInfo, nil
256
255
        }
257
 
        instStat, err := m.InstanceStatus()
258
 
        if err != nil {
 
256
        if instStat, err := m.InstanceStatus(); err != nil {
259
257
                // This should never occur since the machine is provisioned.
260
258
                // But just in case, we reset polled status so we try again next time.
261
259
                logger.Warningf("cannot get current instance status for machine %v: %v", m.Id(), err)
262
 
                instInfo.status = instance.InstanceStatus{status.StatusUnknown, ""}
 
260
                instInfo.status = instance.InstanceStatus{status.Unknown, ""}
263
261
        } else {
264
262
                // TODO(perrito666) add status validation.
265
263
                currentInstStatus := instance.InstanceStatus{
270
268
                        logger.Infof("machine %q instance status changed from %q to %q", m.Id(), currentInstStatus, instInfo.status)
271
269
                        if err = m.SetInstanceStatus(instInfo.status.Status, instInfo.status.Message, nil); err != nil {
272
270
                                logger.Errorf("cannot set instance status on %q: %v", m, err)
273
 
                        }
274
 
                }
275
 
        }
276
 
        providerAddresses, err := m.ProviderAddresses()
277
 
        if err != nil {
278
 
                return instInfo, err
279
 
        }
280
 
        if !addressesEqual(providerAddresses, instInfo.addresses) {
281
 
                logger.Infof("machine %q has new addresses: %v", m.Id(), instInfo.addresses)
282
 
                if err = m.SetProviderAddresses(instInfo.addresses...); err != nil {
283
 
                        logger.Errorf("cannot set addresses on %q: %v", m, err)
284
 
                }
285
 
        }
286
 
        return instInfo, err
 
271
                                return instanceInfo{}, err
 
272
                        }
 
273
                }
 
274
        }
 
275
        if m.Life() != params.Dead {
 
276
                providerAddresses, err := m.ProviderAddresses()
 
277
                if err != nil {
 
278
                        return instanceInfo{}, err
 
279
                }
 
280
                if !addressesEqual(providerAddresses, instInfo.addresses) {
 
281
                        logger.Infof("machine %q has new addresses: %v", m.Id(), instInfo.addresses)
 
282
                        if err := m.SetProviderAddresses(instInfo.addresses...); err != nil {
 
283
                                logger.Errorf("cannot set addresses on %q: %v", m, err)
 
284
                                return instanceInfo{}, err
 
285
                        }
 
286
                }
 
287
        }
 
288
        return instInfo, nil
287
289
}
288
290
 
289
291
// addressesEqual compares the addresses of the machine and the instance information.