Skip to content

Commit cb25eed

Browse files
author
Edison Su
committed
forget to check in code
1 parent df5c4c3 commit cb25eed

4 files changed

Lines changed: 230 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.cloud.utils.storage.encoding;
20+
21+
public class DecodedDataObject {
22+
private String objType;
23+
private Long size;
24+
private String name;
25+
private String path;
26+
private EncodedDataStore store;
27+
28+
public DecodedDataObject(String objType,
29+
Long size,
30+
String name,
31+
String path,
32+
EncodedDataStore store) {
33+
this.objType = objType;
34+
this.size = size;
35+
this.path = path;
36+
this.store = store;
37+
}
38+
39+
public String getObjType() {
40+
return this.objType;
41+
}
42+
43+
public Long getSize() {
44+
return this.size;
45+
}
46+
47+
public String getName() {
48+
return this.name;
49+
}
50+
51+
public String getPath() {
52+
return this.path;
53+
}
54+
55+
public EncodedDataStore getStore() {
56+
return this.store;
57+
}
58+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.cloud.utils.storage.encoding;
20+
21+
import java.net.URI;
22+
import java.net.URISyntaxException;
23+
import java.util.HashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
27+
import edu.emory.mathcs.backport.java.util.Arrays;
28+
29+
public class Decoder {
30+
private static Map<String, String> getParameters(URI uri) {
31+
String parameters = uri.getQuery();
32+
Map<String, String> params = new HashMap<String, String>();
33+
List<String> paraLists = Arrays.asList(parameters.split("&"));
34+
for (String para : paraLists) {
35+
String[] pair = para.split("=");
36+
if (!pair[1].equalsIgnoreCase("null")) {
37+
params.put(pair[0], pair[1]);
38+
}
39+
40+
}
41+
return params;
42+
}
43+
public static DecodedDataObject decode(String url) throws URISyntaxException {
44+
URI uri = new URI(url);
45+
Map<String, String> params = getParameters(uri);
46+
EncodedDataStore store = new EncodedDataStore(params.get(EncodingType.ROLE.toString()),
47+
params.get(EncodingType.STOREUUID.toString()),
48+
params.get(EncodingType.PROVIDERNAME.toString()),
49+
uri.getScheme(),
50+
uri.getScheme() + uri.getHost() + uri.getPath(),
51+
uri.getHost(),
52+
uri.getPath());
53+
54+
Long size = null;
55+
try {
56+
size = Long.parseLong(params.get(EncodingType.SIZE.toString()));
57+
} catch (NumberFormatException e) {
58+
59+
}
60+
DecodedDataObject obj = new DecodedDataObject(params.get(EncodingType.OBJTYPE.toString()),
61+
size,
62+
params.get(EncodingType.NAME.toString()),
63+
params.get(EncodingType.PATH.toString()),
64+
store
65+
);
66+
return obj;
67+
}
68+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.cloud.utils.storage.encoding;
20+
21+
public class EncodedDataStore {
22+
private final String role;
23+
private final String uuid;
24+
private final String providerName;
25+
private final String scheme;
26+
private final String url;
27+
private final String server;
28+
private final String path;
29+
30+
public EncodedDataStore(String role,
31+
String uuid,
32+
String providerName,
33+
String scheme,
34+
String url,
35+
String server,
36+
String path) {
37+
this.role = role;
38+
this.uuid = uuid;
39+
this.providerName = providerName;
40+
this.scheme = scheme;
41+
this.url = url;
42+
this.server = server;
43+
this.path = path;
44+
}
45+
46+
public String getRole() {
47+
return this.role;
48+
}
49+
50+
public String getUuid() {
51+
return this.uuid;
52+
}
53+
54+
public String getProviderName() {
55+
return this.providerName;
56+
}
57+
58+
public String getScheme() {
59+
return this.scheme;
60+
}
61+
62+
public String getUrl() {
63+
return this.url;
64+
}
65+
66+
public String getServer() {
67+
return this.server;
68+
}
69+
70+
public String getPath() {
71+
return this.path;
72+
}
73+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.cloud.utils.storage.encoding;
20+
21+
public enum EncodingType {
22+
//object
23+
OBJTYPE,
24+
SIZE,
25+
NAME,
26+
PATH,
27+
//dataStore
28+
ROLE,
29+
STOREUUID,
30+
PROVIDERNAME
31+
}

0 commit comments

Comments
 (0)