Skip to content

Commit

Permalink
Add Google Cloud Storage support for bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
jhua-vmware committed Oct 24, 2024
1 parent b9e035c commit 35afca5
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 370 deletions.
2 changes: 1 addition & 1 deletion g11n-ws/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ subprojects{
postgresqlVersion = "42.1.4"
druidVersion = "1.1.8"
awsS3Version = "1.12.741"
gcpGcsVersion = "2.42.0"
gcpGcsVersion = "2.42.0"
swaggerVersion = "3.0.0"
icu4jVersion = "60.3"

Expand Down
2 changes: 1 addition & 1 deletion g11n-ws/modules/md-data-api-gcsimpl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
compileOnly("org.springframework.boot:spring-boot-starter-data-jpa")
compileOnly("org.slf4j:slf4j-api:$slf4jVersion")
compileOnly("org.apache.commons:commons-lang3:$commonsLangVersion")
compileOnly("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
compileOnly("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation ("com.google.cloud:google-cloud-storage:2.42.0")
implementation ("com.google.cloud:google-cloud-storage-control:2.42.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,40 @@
@Profile("gcs")
@Repository
public class GcsComponentChannelDao implements IComponentChannelDao {
private static Logger logger = LoggerFactory.getLogger(GcsComponentChannelDao.class);
private static Logger logger = LoggerFactory.getLogger(GcsComponentChannelDao.class);

@Autowired
private GcsClient gcsClient;
@Autowired
private GcsClient gcsClient;

@Autowired
private GcsConfig config;
@Autowired
private GcsConfig config;

@Override
public List<ResultMessageChannel> getTransReadableByteChannels(String productName, String version,
List<String> components, List<String> locales) throws DataException {
logger.debug("GcsComponentChannelDao.getTransReadableByteChannels()-> product={}, version={}, components={}, locales={}",
productName, version, components, locales);
List<ResultMessageChannel> resultChannels = new ArrayList<ResultMessageChannel>();
for (String component : components) {
for (String locale : locales) {
String filePath = GcsUtils.genProductVersionGcsPath(productName, version) + component + ConstantsChar.BACKSLASH
+ ResourceFilePathGetter.getLocalizedJSONFileName(locale);
BlobId blobId = BlobId.of(config.getBucketName(), filePath);
Blob blob = gcsClient.getGcsStorage().get(blobId);
if (blob != null) {
byte[] content = gcsClient.getGcsStorage().readAllBytes(config.getBucketName(), filePath);
if (content != null) {
ByteArrayInputStream is = new ByteArrayInputStream(content);
resultChannels.add(new ResultMessageChannel(component, locale, Channels.newChannel(is)));
}
}
@Override
public List<ResultMessageChannel> getTransReadableByteChannels(String productName, String version,
List<String> components, List<String> locales) throws DataException {
logger.debug("GcsComponentChannelDao.getTransReadableByteChannels()-> product={}, version={}, components={}, locales={}",
productName, version, components, locales);
List<ResultMessageChannel> resultChannels = new ArrayList<ResultMessageChannel>();
for (String component : components) {
for (String locale : locales) {
String filePath = GcsUtils.genProductVersionGcsPath(productName, version) + component + ConstantsChar.BACKSLASH
+ ResourceFilePathGetter.getLocalizedJSONFileName(locale);
BlobId blobId = BlobId.of(config.getBucketName(), filePath);
Blob blob = gcsClient.getGcsStorage().get(blobId);
if (blob != null) {
byte[] content = gcsClient.getGcsStorage().readAllBytes(config.getBucketName(), filePath);
if (content != null) {
ByteArrayInputStream is = new ByteArrayInputStream(content);
resultChannels.add(new ResultMessageChannel(component, locale, Channels.newChannel(is)));
}
}

}
}
logger.debug("fileSize: {}", resultChannels.size());
}
}
logger.debug("fileSize: {}", resultChannels.size());

return resultChannels;
}
return resultChannels;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,67 @@
import com.vmware.vip.messages.data.dao.api.IOneComponentDao;
import com.vmware.vip.messages.data.dao.exception.DataException;
import com.vmware.vip.messages.data.dao.model.ResultI18Message;

/**
* this class get the bundle json from bundle file
*/
@Repository
@Profile("gcs")
public class GcsMultComponentDaoImpl implements IMultComponentDao {
private static Logger logger = LoggerFactory.getLogger(GcsMultComponentDaoImpl.class);
private static Logger logger = LoggerFactory.getLogger(GcsMultComponentDaoImpl.class);

@Autowired
private IOneComponentDao oneComponentDao;
@Autowired
private IOneComponentDao oneComponentDao;

/**
* get the bundle files from gcs service
*/
@Override
public List<String> get2JsonStrs(String productName, String version, List<String> components,
List<String> locales) throws DataException {
logger.debug("begin get2JsonStrs");
List<String> bundles = new ArrayList<>();
if (components == null || locales == null) {
throw new DataException("Gcs No component or locale");
}
for (String component : components) {
for (String locale : locales) {
try {
bundles.add(oneComponentDao.get2JsonStr(productName, version, component, locale));
}catch(DataException e ) {
logger.warn(e.getMessage(), e);
}
}
}
logger.debug("end get2JsonStrs");
return bundles;
}
/**
* get the bundle files from gcs service
*/
@Override
public List<String> get2JsonStrs(String productName, String version, List<String> components, List<String> locales)
throws DataException {
logger.debug("begin get2JsonStrs");
List<String> bundles = new ArrayList<>();
if (components == null || locales == null) {
throw new DataException("Gcs No component or locale");
}
for (String component : components) {
for (String locale : locales) {
try {
bundles.add(oneComponentDao.get2JsonStr(productName, version, component, locale));
} catch (DataException e) {
logger.warn(e.getMessage(), e);
}
}
}
logger.debug("end get2JsonStrs");
return bundles;
}

/**
* get the bundle files and convert to ResultI18Message
*/
@Override
public List<ResultI18Message> get(String productName, String version, List<String> components,
List<String> locales) throws DataException {
logger.debug("begin get");
List<ResultI18Message> bundles = new ArrayList<>();
if (components == null || locales == null) {
throw new DataException("Gcs No component or locale");
}
for (String component : components) {
for (String locale : locales) {
try {
bundles.add(oneComponentDao.get(productName, version, component, locale));
} catch (DataException e) {
throw new DataException("Gcs Failed to get for " + productName
+ ConstantsChar.BACKSLASH + version + ConstantsChar.BACKSLASH + component
+ ConstantsChar.BACKSLASH + locale + ".", e);
/**
* get the bundle files and convert to ResultI18Message
*/
@Override
public List<ResultI18Message> get(String productName, String version, List<String> components, List<String> locales)
throws DataException {
logger.debug("begin get");
List<ResultI18Message> bundles = new ArrayList<>();
if (components == null || locales == null) {
throw new DataException("Gcs No component or locale");
}
for (String component : components) {
for (String locale : locales) {
try {
bundles.add(oneComponentDao.get(productName, version, component, locale));
} catch (DataException e) {
throw new DataException("Gcs Failed to get for " + productName + ConstantsChar.BACKSLASH + version
+ ConstantsChar.BACKSLASH + component + ConstantsChar.BACKSLASH + locale + ".", e);
}
}
}
}
logger.debug("end get");
if (bundles.size() == 0) {
throw new DataException("Gcs No bundle is found.");
}
return bundles;
}
}
logger.debug("end get");
if (bundles.size() == 0) {
throw new DataException("Gcs No bundle is found.");
}
return bundles;
}
}
Loading

0 comments on commit 35afca5

Please sign in to comment.