forget to check in code

This commit is contained in:
Edison Su 2013-01-25 00:24:08 -08:00
parent df5c4c3048
commit cb25eed37a
4 changed files with 230 additions and 0 deletions

View File

@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.cloud.utils.storage.encoding;
public class DecodedDataObject {
private String objType;
private Long size;
private String name;
private String path;
private EncodedDataStore store;
public DecodedDataObject(String objType,
Long size,
String name,
String path,
EncodedDataStore store) {
this.objType = objType;
this.size = size;
this.path = path;
this.store = store;
}
public String getObjType() {
return this.objType;
}
public Long getSize() {
return this.size;
}
public String getName() {
return this.name;
}
public String getPath() {
return this.path;
}
public EncodedDataStore getStore() {
return this.store;
}
}

View File

@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.cloud.utils.storage.encoding;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.emory.mathcs.backport.java.util.Arrays;
public class Decoder {
private static Map<String, String> getParameters(URI uri) {
String parameters = uri.getQuery();
Map<String, String> params = new HashMap<String, String>();
List<String> paraLists = Arrays.asList(parameters.split("&"));
for (String para : paraLists) {
String[] pair = para.split("=");
if (!pair[1].equalsIgnoreCase("null")) {
params.put(pair[0], pair[1]);
}
}
return params;
}
public static DecodedDataObject decode(String url) throws URISyntaxException {
URI uri = new URI(url);
Map<String, String> params = getParameters(uri);
EncodedDataStore store = new EncodedDataStore(params.get(EncodingType.ROLE.toString()),
params.get(EncodingType.STOREUUID.toString()),
params.get(EncodingType.PROVIDERNAME.toString()),
uri.getScheme(),
uri.getScheme() + uri.getHost() + uri.getPath(),
uri.getHost(),
uri.getPath());
Long size = null;
try {
size = Long.parseLong(params.get(EncodingType.SIZE.toString()));
} catch (NumberFormatException e) {
}
DecodedDataObject obj = new DecodedDataObject(params.get(EncodingType.OBJTYPE.toString()),
size,
params.get(EncodingType.NAME.toString()),
params.get(EncodingType.PATH.toString()),
store
);
return obj;
}
}

View File

@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.cloud.utils.storage.encoding;
public class EncodedDataStore {
private final String role;
private final String uuid;
private final String providerName;
private final String scheme;
private final String url;
private final String server;
private final String path;
public EncodedDataStore(String role,
String uuid,
String providerName,
String scheme,
String url,
String server,
String path) {
this.role = role;
this.uuid = uuid;
this.providerName = providerName;
this.scheme = scheme;
this.url = url;
this.server = server;
this.path = path;
}
public String getRole() {
return this.role;
}
public String getUuid() {
return this.uuid;
}
public String getProviderName() {
return this.providerName;
}
public String getScheme() {
return this.scheme;
}
public String getUrl() {
return this.url;
}
public String getServer() {
return this.server;
}
public String getPath() {
return this.path;
}
}

View File

@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.cloud.utils.storage.encoding;
public enum EncodingType {
//object
OBJTYPE,
SIZE,
NAME,
PATH,
//dataStore
ROLE,
STOREUUID,
PROVIDERNAME
}