1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.hdfs.protocol; 19 20 import java.util.Date; 21 22 import org.apache.hadoop.classification.InterfaceAudience; 23 import org.apache.hadoop.classification.InterfaceStability; 24 25 /** 26 * Rolling upgrade information 27 */ 28 @InterfaceAudience.Private 29 @InterfaceStability.Evolving 30 public class RollingUpgradeInfo extends RollingUpgradeStatus { 31 private final long startTime; 32 private long finalizeTime; 33 private boolean createdRollbackImages; 34 RollingUpgradeInfo(String blockPoolId, boolean createdRollbackImages, long startTime, long finalizeTime)35 public RollingUpgradeInfo(String blockPoolId, boolean createdRollbackImages, 36 long startTime, long finalizeTime) { 37 super(blockPoolId, finalizeTime != 0); 38 this.createdRollbackImages = createdRollbackImages; 39 this.startTime = startTime; 40 this.finalizeTime = finalizeTime; 41 } 42 createdRollbackImages()43 public boolean createdRollbackImages() { 44 return createdRollbackImages; 45 } 46 setCreatedRollbackImages(boolean created)47 public void setCreatedRollbackImages(boolean created) { 48 this.createdRollbackImages = created; 49 } 50 isStarted()51 public boolean isStarted() { 52 return startTime != 0; 53 } 54 55 /** @return The rolling upgrade starting time. */ getStartTime()56 public long getStartTime() { 57 return startTime; 58 } 59 60 @Override isFinalized()61 public boolean isFinalized() { 62 return finalizeTime != 0; 63 } 64 65 /** 66 * Finalize the upgrade if not already finalized 67 * @param finalizeTime 68 */ finalize(long finalizeTime)69 public void finalize(long finalizeTime) { 70 if (finalizeTime != 0) { 71 this.finalizeTime = finalizeTime; 72 createdRollbackImages = false; 73 } 74 } 75 getFinalizeTime()76 public long getFinalizeTime() { 77 return finalizeTime; 78 } 79 80 @Override hashCode()81 public int hashCode() { 82 //only use lower 32 bits 83 return super.hashCode() ^ (int)startTime ^ (int)finalizeTime; 84 } 85 86 @Override equals(Object obj)87 public boolean equals(Object obj) { 88 if (obj == this) { 89 return true; 90 } else if (obj == null || !(obj instanceof RollingUpgradeInfo)) { 91 return false; 92 } 93 final RollingUpgradeInfo that = (RollingUpgradeInfo)obj; 94 return super.equals(that) 95 && this.startTime == that.startTime 96 && this.finalizeTime == that.finalizeTime; 97 } 98 99 @Override toString()100 public String toString() { 101 return super.toString() 102 + "\n Start Time: " + (startTime == 0? "<NOT STARTED>": timestamp2String(startTime)) 103 + "\n Finalize Time: " + (finalizeTime == 0? "<NOT FINALIZED>": timestamp2String(finalizeTime)); 104 } 105 timestamp2String(long timestamp)106 private static String timestamp2String(long timestamp) { 107 return new Date(timestamp) + " (=" + timestamp + ")"; 108 } 109 110 public static class Bean { 111 private final String blockPoolId; 112 private final long startTime; 113 private final long finalizeTime; 114 private final boolean createdRollbackImages; 115 Bean(RollingUpgradeInfo f)116 public Bean(RollingUpgradeInfo f) { 117 this.blockPoolId = f.getBlockPoolId(); 118 this.startTime = f.startTime; 119 this.finalizeTime = f.finalizeTime; 120 this.createdRollbackImages = f.createdRollbackImages(); 121 } 122 getBlockPoolId()123 public String getBlockPoolId() { 124 return blockPoolId; 125 } 126 getStartTime()127 public long getStartTime() { 128 return startTime; 129 } 130 getFinalizeTime()131 public long getFinalizeTime() { 132 return finalizeTime; 133 } 134 isCreatedRollbackImages()135 public boolean isCreatedRollbackImages() { 136 return createdRollbackImages; 137 } 138 } 139 } 140