|
27 | 27 | import com.cloud.alert.AlertManager; |
28 | 28 | import com.cloud.exception.InvalidParameterValueException; |
29 | 29 | import com.cloud.exception.StorageConflictException; |
| 30 | +import com.cloud.exception.StorageUnavailableException; |
30 | 31 | import com.cloud.host.Host; |
31 | 32 | import com.cloud.host.HostVO; |
32 | 33 | import com.cloud.host.dao.HostDao; |
|
44 | 45 | import com.cloud.storage.dao.VolumeDao; |
45 | 46 | import com.cloud.user.dao.UserDao; |
46 | 47 | import com.cloud.utils.NumbersUtil; |
47 | | -import com.cloud.utils.UriUtils; |
48 | 48 | import com.cloud.utils.db.DB; |
49 | 49 | import com.cloud.utils.exception.CloudRuntimeException; |
50 | 50 | import com.cloud.vm.VirtualMachineManager; |
|
67 | 67 | import org.apache.log4j.Logger; |
68 | 68 |
|
69 | 69 | import javax.inject.Inject; |
70 | | -import java.io.UnsupportedEncodingException; |
71 | | -import java.net.URI; |
72 | | -import java.net.URISyntaxException; |
73 | | -import java.net.URLDecoder; |
74 | 70 | import java.util.ArrayList; |
75 | 71 | import java.util.List; |
76 | 72 | import java.util.Map; |
@@ -138,64 +134,26 @@ public DataStore initialize(Map<String, Object> dsInfos) { |
138 | 134 |
|
139 | 135 | PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters(); |
140 | 136 |
|
141 | | - UriUtils.UriInfo uriInfo = UriUtils.getUriInfo(url); |
142 | | - |
143 | | - String scheme = uriInfo.getScheme(); |
144 | | - String storageHost = uriInfo.getStorageHost(); |
145 | | - String storagePath = uriInfo.getStoragePath(); |
146 | | - try { |
147 | | - if (scheme == null) { |
148 | | - throw new InvalidParameterValueException("scheme is null " + url + ", add nfs:// (or cifs://) as a prefix"); |
149 | | - } else if (scheme.equalsIgnoreCase("nfs")) { |
150 | | - if (storageHost == null || storagePath == null || storageHost.trim().isEmpty() || storagePath.trim().isEmpty()) { |
151 | | - throw new InvalidParameterValueException("host or path is null, should be nfs://hostname/path"); |
152 | | - } |
153 | | - } else if (scheme.equalsIgnoreCase("cifs")) { |
154 | | - // Don't validate against a URI encoded URI. |
155 | | - URI cifsUri = new URI(url); |
156 | | - String warnMsg = UriUtils.getCifsUriParametersProblems(cifsUri); |
157 | | - if (warnMsg != null) { |
158 | | - throw new InvalidParameterValueException(warnMsg); |
159 | | - } |
160 | | - } else if (scheme.equalsIgnoreCase("sharedMountPoint")) { |
161 | | - if (storagePath == null) { |
162 | | - throw new InvalidParameterValueException("host or path is null, should be sharedmountpoint://localhost/path"); |
163 | | - } |
164 | | - } else if (scheme.equalsIgnoreCase("rbd")) { |
165 | | - if (storagePath == null) { |
166 | | - throw new InvalidParameterValueException("host or path is null, should be rbd://hostname/pool"); |
167 | | - } |
168 | | - } else if (scheme.equalsIgnoreCase("gluster")) { |
169 | | - if (storageHost == null || storagePath == null || storageHost.trim().isEmpty() || storagePath.trim().isEmpty()) { |
170 | | - throw new InvalidParameterValueException("host or path is null, should be gluster://hostname/volume"); |
171 | | - } |
172 | | - } |
173 | | - } catch (URISyntaxException e) { |
174 | | - throw new InvalidParameterValueException(url + " is not a valid uri"); |
175 | | - } |
176 | | - |
177 | 137 | String tags = (String)dsInfos.get("tags"); |
178 | 138 | Map<String, String> details = (Map<String, String>)dsInfos.get("details"); |
179 | 139 |
|
180 | 140 | parameters.setTags(tags); |
181 | 141 | parameters.setDetails(details); |
182 | 142 |
|
183 | | - String hostPath = null; |
184 | | - try { |
185 | | - hostPath = URLDecoder.decode(storagePath, "UTF-8"); |
186 | | - } catch (UnsupportedEncodingException e) { |
187 | | - s_logger.error("[ignored] we are on a platform not supporting \"UTF-8\"!?!", e); |
188 | | - } |
189 | | - if (hostPath == null) { // if decoding fails, use getPath() anyway |
190 | | - hostPath = storagePath; |
191 | | - } |
| 143 | + String scheme = dsInfos.get("scheme").toString(); |
| 144 | + String storageHost = dsInfos.get("host").toString(); |
| 145 | + String hostPath = dsInfos.get("hostPath").toString(); |
| 146 | + String uri = String.format("%s://%s%s", scheme, storageHost, hostPath); |
| 147 | + |
192 | 148 | Object localStorage = dsInfos.get("localStorage"); |
193 | | - if (localStorage != null) { |
194 | | - hostPath = hostPath.replaceFirst("/", ""); |
| 149 | + if (localStorage != null) { |
| 150 | + hostPath = hostPath.contains("//") ? hostPath.replaceFirst("/", "") : hostPath; |
195 | 151 | hostPath = hostPath.replace("+", " "); |
196 | 152 | } |
197 | | - String userInfo = uriInfo.getUserInfo(); |
198 | | - int port = uriInfo.getPort(); |
| 153 | + |
| 154 | + String userInfo = dsInfos.get("userInfo") != null ? dsInfos.get("userInfo").toString() : null; |
| 155 | + int port = dsInfos.get("port") != null ? Integer.parseInt(dsInfos.get("port").toString()) : -1; |
| 156 | + |
199 | 157 | if (s_logger.isDebugEnabled()) { |
200 | 158 | s_logger.debug("createPool Params @ scheme - " + scheme + " storageHost - " + storageHost + " hostPath - " + hostPath + " port - " + port); |
201 | 159 | } |
@@ -312,16 +270,16 @@ public DataStore initialize(Map<String, Object> dsInfos) { |
312 | 270 | parameters.setPort(0); |
313 | 271 | parameters.setPath(hostPath); |
314 | 272 | } else { |
315 | | - s_logger.warn("Unable to figure out the scheme for URI: " + uriInfo); |
316 | | - throw new IllegalArgumentException("Unable to figure out the scheme for URI: " + uriInfo); |
| 273 | + s_logger.warn("Unable to figure out the scheme for URI: " + scheme); |
| 274 | + throw new IllegalArgumentException("Unable to figure out the scheme for URI: " + scheme); |
317 | 275 | } |
318 | 276 | } |
319 | 277 |
|
320 | 278 | if (localStorage == null) { |
321 | 279 | List<StoragePoolVO> pools = primaryDataStoreDao.listPoolByHostPath(storageHost, hostPath); |
322 | 280 | if (!pools.isEmpty() && !scheme.equalsIgnoreCase("sharedmountpoint")) { |
323 | 281 | Long oldPodId = pools.get(0).getPodId(); |
324 | | - throw new CloudRuntimeException("Storage pool " + uriInfo + " already in use by another pod (id=" + oldPodId + ")"); |
| 282 | + throw new CloudRuntimeException("Storage pool " + hostPath + " already in use by another pod (id=" + oldPodId + ")"); |
325 | 283 | } |
326 | 284 | } |
327 | 285 |
|
@@ -550,7 +508,16 @@ private HypervisorType getHypervisorType(long hostId) { |
550 | 508 |
|
551 | 509 | @Override |
552 | 510 | public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { |
553 | | - dataStoreHelper.attachHost(store, scope, existingInfo); |
| 511 | + DataStore dataStore = dataStoreHelper.attachHost(store, scope, existingInfo); |
| 512 | + if(existingInfo.getCapacityBytes() == 0){ |
| 513 | + try { |
| 514 | + storageMgr.connectHostToSharedPool(scope.getScopeId(), dataStore.getId()); |
| 515 | + } catch (StorageUnavailableException ex) { |
| 516 | + s_logger.error("Storage unavailable ",ex); |
| 517 | + } catch (StorageConflictException ex) { |
| 518 | + s_logger.error("Storage already exists ",ex); |
| 519 | + } |
| 520 | + } |
554 | 521 | return true; |
555 | 522 | } |
556 | 523 |
|
|
0 commit comments