Skip to content

Commit

Permalink
Update service last modified timestamp when public keys are added and…
Browse files Browse the repository at this point in the history
…/or deleted
  • Loading branch information
Henry Avetisyan committed Mar 31, 2017
1 parent 7ff6485 commit e90f43b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion servers/zms/scripts/make_stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RDL_PROVIDER_FILE=../../core/zms/src/main/rdl/Provider.rdl
echo "Generate the server stubs"
rdl -s generate -b="/v1" -o="src/main/java" java-server $RDL_ZMS_FILE

echo "Generate the provier client library"
echo "Generate the provider client library"
rdl -s generate -o="src/main/java" java-client $RDL_PROVIDER_FILE

echo "Removing not needed ZMS Server file..."
Expand Down
6 changes: 4 additions & 2 deletions servers/zms/src/main/java/com/yahoo/athenz/zms/DBService.java
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,9 @@ void executePutPublicKeyEntry(ResourceContext ctx, String domainName, String ser
" in service " + ZMSUtils.serviceResourceName(domainName, serviceName), caller);
}

// update our domain time-stamp and save changes
// update our service and domain time-stamp and save changes

con.updateServiceIdentityModTimestamp(domainName, serviceName);
saveChanges(con, domainName);

// audit log the request
Expand Down Expand Up @@ -875,8 +876,9 @@ void executeDeletePublicKeyEntry(ResourceContext ctx, String domainName, String
" in service " + ZMSUtils.serviceResourceName(domainName, serviceName), caller);
}

// update our domain time-stamp and save changes
// update our service and domain time-stamp and save changes

con.updateServiceIdentityModTimestamp(domainName, serviceName);
saveChanges(con, domainName);

// audit log the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public interface ObjectStoreConnection extends Closeable {
boolean updateServiceIdentity(String domainName, ServiceIdentity service);
boolean deleteServiceIdentity(String domainName, String serviceName);
List<String> listServiceIdentities(String domainName);

boolean updateServiceIdentityModTimestamp(String domainName, String serviceName);

PublicKeyEntry getPublicKeyEntry(String domainName, String serviceName, String keyId);
boolean insertPublicKeyEntry(String domainName, String serviceName, PublicKeyEntry publicKey);
boolean updatePublicKeyEntry(String domainName, String serviceName, PublicKeyEntry publicKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,19 @@ public List<String> listServiceIdentities(String domainName) {
return list;
}

@Override
public boolean updateServiceIdentityModTimestamp(String domainName, String serviceName) {

DomainStruct domainStruct = getDomainStruct(domainName);
if (domainStruct == null) {
throw ZMSUtils.error(ResourceException.NOT_FOUND, "domain not found", "updateServiceIdentityModTimestamp");
}
ServiceIdentity service = getServiceObject(domainStruct, serviceName);
service.setModified(Timestamp.fromCurrentTime());
putDomainStruct(domainName, domainStruct);
return true;
}

@Override
public PublicKeyEntry getPublicKeyEntry(String domainName, String serviceName, String keyId) {
DomainStruct domainStruct = getDomainStruct(domainName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public class JDBCConnection implements ObjectStoreConnection {
+ "(name, provider_endpoint, executable, svc_user, svc_group, domain_id) VALUES (?,?,?,?,?,?);";
private static final String SQL_UPDATE_SERVICE = "UPDATE service SET "
+ "provider_endpoint=?, executable=?, svc_user=?, svc_group=? WHERE service_id=?;";
private static final String SQL_UPDATE_SERVICE_MOD_TIMESTAMP = "UPDATE service "
+ "SET modified=CURRENT_TIMESTAMP(3) WHERE service_id=?;";
private static final String SQL_DELETE_SERVICE = "DELETE FROM service WHERE domain_id=? AND name=?;";
private static final String SQL_GET_SERVICE_ID = "SELECT service_id FROM service WHERE domain_id=? AND name=?;";
private static final String SQL_LIST_SERVICE = "SELECT name FROM service WHERE domain_id=?;";
Expand Down Expand Up @@ -1056,6 +1058,30 @@ public boolean updateRoleModTimestamp(String domainName, String roleName) {
return (affectedRows > 0);
}

@Override
public boolean updateServiceIdentityModTimestamp(String domainName, String serviceName) {

int affectedRows = 0;
final String caller = "updateServiceIdentityModTimestamp";

int domainId = getDomainId(con, domainName);
if (domainId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_DOMAIN, domainName);
}
int serviceId = getServiceId(con, domainId, serviceName);
if (serviceId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_SERVICE, ZMSUtils.serviceResourceName(domainName, serviceName));
}

try (PreparedStatement ps = con.prepareStatement(SQL_UPDATE_SERVICE_MOD_TIMESTAMP)) {
ps.setInt(1, serviceId);
affectedRows = executeUpdate(ps, caller);
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
return (affectedRows > 0);
}

@Override
public boolean deleteRole(String domainName, String roleName) {

Expand Down

0 comments on commit e90f43b

Please sign in to comment.